0

I want to upload an image in three 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.

0

2 Answers 2

2

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!

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.