0
我創建了下面的代碼創建一個zip文件創建一個zip文件。我根據$ job_number(我從全局的$ _GET數組中獲取)從數據庫中提取文件列表,然後嘗試將它們添加到zip文件中。不能與PHP
這部分工作正常。它從數據庫中提取文件列表,正如我通過print_r
回顯或傾銷結果所看到的。
唯一的問題是沒有建立在所有的.zip文件。我看不出我出錯的地方。
$sth = $conn->prepare('SELECT `dp_filename` FROM damage_pics WHERE dp_job_number = :job_number');
$sth->bindParam(':job_number', $job_number);
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$zip = new ZipArchive();
$zip->open('example5.zip', ZipArchive::CREATE);
$result = $sth->fetchAll();
echo '<pre>';
print_r($result);
foreach ($result as $file)
{
// just echoing for testing purposes to see if file name is created correctly.
$image = $file['dp_filename'];
echo $image . "<br />";
$zip->addFile("uploads/{$image}");
}
$zip->close();
你在哪裏保存zip文件?該目錄是否可寫? – pregmatch 2013-05-11 12:42:32
確保ZipArchive安裝在您的PHP版本上。 – 2013-05-11 12:59:04