在codeigniter中上传图片
问题描述:
我想上传三张图片中的图片。我的文件夹结构如下: upload/large,upload/original,upload/thumb。 如何使用codeigniters的“上传”库将调整大小后的图像存储到这些文件夹中。在codeigniter中上传图片
答
我与钠同意,你需要接受更多的答案。
然而,对于这样的问题: 它看起来对我像你其实只是上传到原来的文件夹,然后用这个复制的图像库,所以,请尝试以下操作:
$config['upload_path'] = './upload/original';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '500';
$config['max_height'] = '300';
$this->load->library('upload', $config);
$this->upload->do_upload()
$upload_data = $this->upload->data();
$copies = array(
array('dir' => 'upload/large', 'x' => 1000, 'y' => 600), //note: x&y could be replaced with a percentage or ratio etc.
array('dir' => 'upload/thumbnail', 'x' => 100, 'y' => 60)
);
foreach($copies as $copy)
{
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin/';
$config['source_image'] = $upload_data['full_path'];
$config['new_image'] = $copy['dir'] . $upload_data['file_name'];
$config['maintain_ratio'] = TRUE;
$config['width'] = $copy['x'];
$config['height'] = $copy['y'];
$config['master_dim'] = 'width';
$this->image_lib->initialize($config);
$this->image_lib->resize();
}
希望这有助于!
答
您应该更改配置阵列中的“upload_path”值。
这是某种形式的代码,你可以使用:
$config['upload_path'] = './uploads/';
$this->load->library('upload', $config);
谈到用户指南: http://codeigniter.com/user_guide/libraries/file_uploading.html
谢谢你这么多..这对我有用。:) – 2011-05-03 12:18:37