php - Change storage folder when create zip -
i use code create zip file php zip correctly created, have little trouble when download zip.
on browser, zip name appear this
.._.._storage_temp_2013-09-03-1378245354.zip
i'm mantain only
2013-09-03-1378245354.zip
here code use:
$files = array($frente, $verso); //$zipname = '../../storage/file.zip'; $zipname = "../../storage/temp/".date('y-m-d')."-".time().".zip"; // zip name $zip = new ziparchive; $zip->open($zipname, ziparchive::create); foreach ($files $file) { $new_filename = substr($file,strrpos($file,'/') + 1); $zip->addfile($file,$new_filename); //$zip->addfromstring(basename($file), file_get_contents($file)); } $zip->close(); header('content-type: application/zip'); header('content-disposition: attachment; filename='.$zipname); header('content-length: ' . filesize($zipname)); ob_clean(); flush(); readfile($zipname)
i have solved in way:
$new_zipname = substr($zipname,strrpos($zipname,'/') + 1); header('content-type: application/zip'); header('content-disposition: attachment; filename='.$new_zipname);
Comments
Post a Comment