0

I have a form which sends 2 images to my controller

 <form action="generate" method="post" accept-charset="utf-8" enctype="multipart/form-data">
    <input type="file" name="image1" size="20" /> 
    <input type="file" name="image2" size="20" /> 
    <input type="submit" class="btn btn-success" value="upload" />
</form>

Now in my controller i want to compress image1 and image2 to zip format and save it in a folder. I also see this documentation but i don't know how to add 2 images in one file .

Any ideas?Thanks in advance.

1 Answer 1

1

Codeigniter has a library meant for helping with zip utilities:

You can load it like this:

$this->load->library('zip');

Then the class object can be accessed as:

$this->zip

For zipping a file, you can do this:

$path1 = '/path/to/photo1.jpg';  
$path2 = '/path/to/photo2.jpg';    
$this->zip->read_file($path1); 
$this->zip->read_file($path2); 
$this->zip->archive('/path/to/folder/my_images.zip');

You can read more at CodeIgniter's Zip Library Documentation

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

5 Comments

I want to add to $_FILES['image1'] and $_FILES['image2'] to add_data
You can use read_file() for that. Please check my updated answer
Should i change $path1 to $_FILES['image1']
You have to provide the path to where the images it. The $_FILES array has that information in one of its indices
this is my Array Array ( [image1] => Array ( [name] => temp1.png [type] => image/png [tmp_name] => /tmp/php8hwoG1 [error] => 0 [size] => 6342 ) should i pass $_FILES['image1']['tmp_name'] ?

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.