Forum Moderators: coopster
right now i have it overwrite the existing foo.zip file
is there a way to make it so the file is not saved? as in it is created just to send to the user but doesn't actually stay on the server?
thanks
I'd say that depending on how many people you have downloading the file, creating it each time might be a bit processor-intensive and unnecessarily so. Would running a cron job to create the file every few hours - or whatever's appropriate - work for you?
The zip library mentioned is Read Only Access. You aren't going to be able to accomplish your goals using the Zip File Functions. You are going to want to have a look at the Zlib Compression Functions [php.net] instead. There is an example there that shows you how to accomplish most of what you are asking, including the deletion (unlink) of the temporary file.
<?
function replace_ampersand($file, $bool){
if($bool==true){
return str_replace("&", "@@@", $file);
}else{
return str_replace("@@@", "&", $file);
}
}
session_start();
$myfolder = "MYFOLDER"; //folder to download
$folder = replace_ampersand($myfolder, false);
$download_file = "download[".preg_replace("#[^A-Za-z,0-9,=]#", "_", $myfolder)."].zip";
$systemcall = "/usr/bin/zip -r /tmp/$download_file $folder";
@exec($systemcall);header("Content-disposition: attachment; filename=$download_file");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Pragma: public");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Expires: 0");
$client=getenv("HTTP_USER_AGENT");
$size = filesize("/tmp/$download_file");
header("Content-Length: $size");
$hdl = fopen("/tmp/$download_file" , "r");
fpassthru($hdl);
@unlink("/tmp/$download_file");
?>
[zend.com...]
;o)
(or
[edited by: jatar_k at 2:19 am (utc) on May 17, 2004]
[edit reason] linked up url [/edit]