I tried to make an download button to zip my files. When I set multiple files in the array it gives the error
When I hardcode "files/path/to/8717953176714.jpg" it works.
Here is my code:
<?php
//print_r($_POST["foto"]);
$files = array($_POST["foto"]);
$random = rand(1000000000, 9999999999);
$zipname = 'file'.$random.'.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
$zip->close();
$filename = $zipname;
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-length: ' . filesize($filename));
readfile($filename);
$file = fopen('iplog.txt', 'a', 1);
$ipz = getenv("REMOTE_ADDR");
$text = "$ipz
";
fwrite($file, $text);
fclose($file);
?>
</div>
The problem was. I made an array into an array. So it didn't get the good path.
$files = $_POST["foto"];
instead of
$files = array($_POST["foto"]);
</div>
try this change :
$zipname =getcwd()'/file'.$random.'.zip';