Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP save zip to disk

I want to zip files uploaded by a user to a certain Location. While the upload part works, I have no Idea how to zip the file. I am able to create a zip, but do not now how to actually save it to a disk.

like image 332
gibberish Avatar asked Feb 02 '13 04:02

gibberish


People also ask

How do I zip a php file?

In the browser, enter https://localhost/zip.php as the url and the file will be zipped. After this a new zip file is created named 'file'.

How can I download multiple zip files in php?

ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) == true) { foreach($validFiles as $file) { $zip->addFile($file,$file); } $zip->close(); return file_exists($destination); }else{ return false; } }else{ return false; } } $fileName = 'myzipfile. zip'; $files = array('uploads/profile1. jpeg', 'uploads/profile2.

How can I download zip file from URL in php?

To Download And Extract Zip File It Takes Only One Step:-$url = "http://anysite.com/file.zip"; $zip_file = "folder/downloadfile.

How do I zip a folder in Linux?

The easiest way to zip a folder on Linux is to use the “zip” command with the “-r” option and specify the file of your archive as well as the folders to be added to your zip file. You can also specify multiple folders if you want to have multiple directories compressed in your zip file.


1 Answers

Simply pass the desired destination path to the zip when creating it:

$path = 'path/to/file.zip';
$zip = new ZipArchive();
$zip->open($path, ZipArchive::CREATE);
// add contents...
$zip->close();
like image 130
Havelock Avatar answered Oct 03 '22 11:10

Havelock