Forum Moderators: coopster

Message Too Old, No Replies

auto download

is it possible?

         

WhosAWhata

3:34 pm on May 9, 2004 (gmt 0)

10+ Year Member



i have a folder (foo/) that changes often, and i want a user to be able to download foo.zip which is generated at that time

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

jtnt

10:09 pm on May 9, 2004 (gmt 0)

10+ Year Member



Sure, there is zip file functionality in PHP, although not enabled by default. Check this page for more info: [us2.php.net...]

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?

WhosAWhata

4:17 am on May 10, 2004 (gmt 0)

10+ Year Member



this particular site isn't too busy so it shouldn't bee too bad (and cron jobs are not supported by my host -nice suggestion though i thought of that too a while back)

WhosAWhata

4:26 am on May 10, 2004 (gmt 0)

10+ Year Member



sorry, i really don't get the zip functions... here's my start (my meager start)

<?
$folder = "folder/";
$zip = gzcompress($folder,9);
header("Content-Encoding: gzip");
echo $zip;
?>

has no functionality whatsoever

help appreciated

coopster

3:49 pm on May 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



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?

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.

WhosAWhata

1:01 am on May 12, 2004 (gmt 0)

10+ Year Member



i browsed that section, but failed to find anything of use
where should i start?

WhosAWhata

1:22 am on May 12, 2004 (gmt 0)

10+ Year Member



i tried to modify some code i found on another site, but it seems to just echo the strange character mix that would be found by opening the file in notepad



<?
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");
?>


WhosAWhata

6:54 pm on May 13, 2004 (gmt 0)

10+ Year Member



is it a header problem?

corz

12:15 am on May 17, 2004 (gmt 0)

10+ Year Member



try here..

[zend.com...]

;o)
(or

[edited by: jatar_k at 2:19 am (utc) on May 17, 2004]
[edit reason] linked up url [/edit]

WhosAWhata

2:16 am on May 17, 2004 (gmt 0)

10+ Year Member



it was, as i suspected a header problem
header("Content-type: application/octetstream");
needed to be
header("Content-type: application/octet-stream");