Page 2 of 2
Posted: Fri May 28, 2004 11:06 am
by Grim...
PatrickG: Ah yes - bravo

Posted: Fri May 28, 2004 11:10 am
by glennn3
patrikG wrote:If you want to use a custom session-handler (logging the session in the database) and use each client's session-id to name the particular file (e.g. "myfilename_adc74dc8a458dca586c7a52.pdf"). In the session garbage collection, you scan the clients' folders and delete all files that match "my_filename_".$session_id.".pdf".
That way you don't need to worry about timing - a session either times out or is terminated at which point your garbage collection comes into play - and: it's neat and generic.
good deal - thanks...
Posted: Fri May 28, 2004 11:21 am
by patrikG
If you want to avoid the database: are you using fopen to read the file to download before the fpassthru? If so, then you shouldn't be able to unlink it unless you've closed it with fclose.
So, in theory, you should be able to
1. open the file using fopen
2. initiate the download with fpassthru
3. after the download is finished, you close it with fclose and run a
while(!unlink($theFileName)){
}
Obviously, this is a quick and dirty solution... - haven't tried it, but it's something shouldn't be too far from the solution, if it doesn't work.
Edit: moved to php-code
Posted: Fri May 28, 2004 11:28 am
by glennn3
yes, i don't want to mess with sessions in this Very cheap website.
originally the file was just being downloaded without php (just by clicking on it - he was miraculously able to teach them how to save it to their pc that way
i've never used fpassthru, so i'm unaware of it. i'm a novice at scripint; had no need to use fopen - i'll research the the fpassthru function, tho. that's probably what i need, and then, yes, just stick the unlink() at the end.
quick and dirty is just what i'm looking for. thanks P.
Posted: Fri May 28, 2004 11:49 am
by dave420
Why don't you just make the PHP pass the file to the client, then when the PHP code has passed the last byte, delete the file? It works fine. No cron jobs. No hassle

Posted: Fri May 28, 2004 11:57 am
by glennn3
THAT's exactly what i'm talking about. just don't know the function for that - i've been trying
Code: Select all
$source="file.exe";
$dest="C:\test\file.exe";
copy($source_file, $dest_file);
if (!copy($source, $dest)) {
print ("failed to copy $dest...\n");
}
but this obviously doesn't want to write to my local machine...
my noviceness is showing, i know...
thanks
Posted: Fri May 28, 2004 12:04 pm
by dave420
Code: Select all
$fn="c:/path/to/file";
set_time_limit(0);
$fp=fopen($fn, "rb");
while (!feof($fp)) {
echo fread($fp, 40960);
flush();
}
fclose($fp);
unlink($fn);
Posted: Fri May 28, 2004 12:20 pm
by glennn3
thanks, but we won't want the file to open - it's an exe... isn't there a function that will just open a save as dialog box? maybe this shouldn't be done in php, like Grimm said...
thanks
Posted: Mon May 31, 2004 12:05 am
by slimsam1
Why not:
send the headers
use readfile to send data to browser
unlink same file we just used readfile on
?
Posted: Mon May 31, 2004 12:10 am
by slimsam1
Code: Select all
<?php
$fn="c:/path/to/file";
set_time_limit(0);
$fp=fopen($fn, "rb");
while (!feof($fp)) {
echo fread($fp, 40960);
flush();
}
fclose($fp);
unlink($fn);
?>
glennn3 wrote:thanks, but we won't want the file to open - it's an exe... isn't there a function that will just open a save as dialog box? maybe this shouldn't be done in php, like Grimm said...
thanks
Did you try that already? I think the download box depends on browser settings and the headers sent to the browser.