PHP下载多个文件为zip错误

问题描述:

我试图制作一个下载按钮来压缩我的文件。当我在数组中设置多个文件它给出了错误enter image description herePHP下载多个文件为zip错误

当我硬编码“文件/路径/到/ 8717953176714.jpg”它的作品。

这里是我的代码:

<?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\n"; 
 
fwrite($file, $text); 
 
fclose($file); 
 

 
?>

的问题了。我将数组创建为一个数组。所以它没有得到好的道路。

$files = $_POST["foto"];

,而不是

$files = array($_POST["foto"]);

尝试这种变化:

$zipname =getcwd()'/file'.$random.'.zip'; 
+0

给我什么。不起作用:( – Horizon

+0

echo $ zipname;检查路径是否正常脚本被允许在那里写入 –