stream - php ziparchive readfile, no such file found error -
i encountering error:
[23-jul-2013 16:26:15 america/new_york] php warning: readfile(resumes.zip): failed open stream: no such file or directory in /home/mcaplace/public_html/download.php on line 24
this code:
<?php /*foreach($_post['files'] $check) { echo $check;}*/ function zipfilesanddownload($file_names,$archive_file_name,$file_path) { $zip = new ziparchive(); //create file , throw 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 archive foreach($file_names $files) { $zip->addfile($file_path.$files,$files); /*if(file_exists($file_path.$files)) //." ".$files."<br>"; echo "yes";*/ } $zip->close(); //then send headers foce download 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 passing file names thae array directly use following method $file_names = $_post['files']; //if getting file name database means use following method //include db connection $archive_file_name='resumes.zip'; $file_path=$_server['document_root']."/resumes/"; zipfilesanddownload($file_names,$archive_file_name,$file_path); ?>
you have couple things wrong first off ziparchive::create not correct should ziparchive::create or ziparchive::overwrite (overwrite if not deleting zip file).
next pathing wrong. not telling readfile() absolute path file. need give absolute paths zip file saved , it's read from.
also find unlikel root folder site writable. moved zip resumes folder code below. tend stay away $_server['document_root'] self , use realpath() function.
and lastly have make sure ever folder zip file being created has 777 permissions on it.
here complete code change
<?php /*foreach($_post['files'] $check) { echo $check;}*/ function zipfilesanddownload($file_names,$archive_file_name,$file_path) { $zip = new ziparchive(); //create file , throw error if unsuccessful if ($zip->open($file_path.$archive_file_name, ziparchive::overwrite )!==true) { exit("cannot open <$archive_file_name>\n"); } //add each files of $file_name array archive foreach($file_names $files) { $zip->addfile($file_path.$files,$files); /*if(file_exists($file_path.$files)) //." ".$files."<br>"; echo "yes";*/ } $zip->close(); //then send headers foce download zip file header("content-type: application/zip"); header("content-disposition: attachment; filename=$archive_file_name"); header("pragma: no-cache"); header("expires: 0"); readfile($file_path.$archive_file_name); exit; } //if passing file names thae array directly use following method $file_names = array('test.txt'); //if getting file name database means use following method //include db connection $archive_file_name='resumes.zip'; $file_path=$_server['document_root']."/resumes/"; zipfilesanddownload($file_names,$archive_file_name,$file_path); ?>
Comments
Post a Comment