i have written script add files zip archive , download on form submission.
file path determined according submitted data. first, file paths determined , checked existence , added array.
then files added zipped archive , downloaded. following code. takes time. increased maximum execution time
120 seconds
still doesn't work.
if (isset($valid_files)) { if(count($valid_files)) { $zip = new ziparchive(); $zip_name = "file_name.zip"; $zip_path = "files/$zip_name"; $opened = $zip->open( $zip_path, ziparchive::create | ziparchive::overwrite ); if( $opened !== true ){ die("cannot open {$zip_name} writing."); } foreach($valid_files $key => $file) { $f_name = $key.ext"; $zip->addfile($file,$f_name); } $zip->close(); if (file_exists($zip_path)) { header( "pragma: public" ); header( "expires: 0" ); header( "cache-control: must-revalidate, post-check=0, pre-check=0" ); header( "cache-control: public" ); header( "content-description: file transfer" ); header( "content-type: application/zip" ); header( "content-disposition: attachment; filename=\"" . $zip_name . "\"" ); header( "content-transfer-encoding: binary" ); header( "content-length: " . filesize( $zip_path ) ); readfile($zip_path); die; } } }
Comments
Post a Comment