开发者

image upload in codeigniter

I want to upload an image in t开发者_开发百科hree foler. My folder structure is like: upload/large,upload/original,upload/thumb. How to store the image after resizing into these folders using codeigniters 'upload' library.


I agree with Natrium, you need to accept more answers.

However, for this question: It looks to me like you're only actually uploading to the original folder and then using the image library on this copy, so, try the following:

$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();
}

Hope this helps!


You should just change the "upload_path" value in your configuration Array.

Here is some kind of code you could use :

    $config['upload_path'] = './uploads/';

    $this->load->library('upload', $config);

Referring to the User Guide : http://codeigniter.com/user_guide/libraries/file_uploading.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜