-1

Hello i am just creating a zip file using php but the file not being created however it is return boolean true i dont know whats problem going on. before created what did i do

  1. i installed php zip in my Ubuntu using sudo apt-get install php-zip and after installation i restarted my apache server.

  2. create a zip.php file file and write this code

$zip = new ZipArchive; //var_dump($zip->open('test.zip',ZipArchive::CREATE)); $f = $zip->open('zip/myzip.zip',ZipArchive::CREATE); var_dump($f);

this code return true but file not being created

  1. no any file permission issue i already given it to my directory.
Shakti Sisodiya
  • 218
  • 2
  • 5
  • 14

1 Answers1

2

Empty Zip can not be created, You have to select some files to create a zip file. Try below code

$zip = new ZipArchive();
$filename = "test.zip";

if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}
$zip->addFile("a.jpg","b.jpg");
$zip->close();

replace 'a.jpg', 'b.jpg' from your files.

  • 1
    thank you dear it is working code but i have still confusion that if a zip file not created till now then how can it returns true. – Shakti Sisodiya May 16 '17 at 07:26