我遇到了这个错误:
[23-Jul-2013 16:26:15 America/New_York] PHP 警告:readfile(Resumes.zip):无法打开流:第 24 行的 /home/mcaplace/public_html/download.php 中没有此类文件或目录
这是代码:
<?php
/*foreach($_POST['files'] as $check) {
echo $check;}*/
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
/*if(file_exists($file_path.$files)) //." ".$files."<br>";
echo "yes";*/
}
$zip->close();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile($archive_file_name);
exit;
}
//If you are passing the file names to thae array directly use the following method
$file_names = $_POST['files'];
//if you are getting the file name from database means use the following method
//Include DB connection
$archive_file_name='Resumes.zip';
$file_path=$_SERVER['DOCUMENT_ROOT']."/resumes/";
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
?>