I am adding files to Zip with php using the following php script.
<?php
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
session_start();
$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
$filesinSession = $_SESSION['files'];
$filesToAdd = explode(';', $filesinSession);
for($i = 1 ; $i <= sizeof($filesToAdd)-1 ; $i++)
{
//echo $filesToAdd[$i]."<br>";
$zip->addFile($filesToAdd[$i]);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
header('Content-type: application/zip');
header('Content-disposition: filename="' . $zip_name . '"');
header("Content-length: " . filesize($zip_name));
$zip_file = file_get_contents($zip_name);
readfile($zip_name);
exit();
?>
note:session contains file name semicolon separated.
the file generated as a result of above code execution. is damaged when i open that file in sublime text. it shows following error.
///////////////////zip opened in sublime text///////////////////////////////////
Warning: filesize(): stat failed for 1508220713.zip in C:\xampp\htdocs\HMApp1\download.php on line 21
Warning: file_get_contents(1508220713.zip): failed to open stream: No such file or directory in C:\xampp\htdocs\HMApp1\download.php on line 22
Warning: readfile(1508220713.zip): failed to open stream: No such file or directory in C:\xampp\htdocs\HMApp1\download.php on line 23