Page 1 of 2
script to download AND delete a file...
Posted: Fri May 28, 2004 10:37 am
by glennn3
i'm providing downloadable executables for several particularly ignorant clients who i cannot trust to be able to delete the file once downloaded (this is necessary) - i'd be very appreciative of some help with a script that would first download a file and then delete the same file...
thanks so much,
gn
Posted: Fri May 28, 2004 10:38 am
by magicrobotmonkey
uurrmm I dont believe that php can delete something client-side - it just doesnt seem right to me. What are they doing with these files? Are you sure that its something they need to download?
Posted: Fri May 28, 2004 10:40 am
by Joe
Why would someone want to download a file and then delete so others cannot download it for themselves. Something sounds wrong here dude!
*edit* Wooo everyone I changed my avatar for once...
Posted: Fri May 28, 2004 10:45 am
by glennn3
magicrobotmonkey wrote:uurrmm I dont believe that php can delete something client-side - it just doesnt seem right to me. What are they doing with these files? Are you sure that its something they need to download?
what are you talking about ? a simple unlink() function can be ran to do so. i just need it to be done autmatically when the download is performed.
am i certain that it's something that they need to download? are you serious?
am i in the right forum...?
Posted: Fri May 28, 2004 10:47 am
by Grim...
You wouldn't want PHP to do that on it's own - it would need some help from JavaScript - it is possible, but unreliable.
First, get the size of the file. Build a page with a JavaScript re-director pointing at the page with the 'delete file' PHP script. Work out how long it should take the download to complete, and add a percentage as a safety margin. Also use JavaScript to open a new window which starts the download.
When the time is up, the JavaScript redirects to the delete page, and the file is deleted.
You could use the php wait() command, but it would probably time out before the download is completed, depending, of course, on the size of the files vs connection.
How big are the files?
Posted: Fri May 28, 2004 10:49 am
by Grim...
Glenn - no need to be like that - your first post was worded so it read like you wanted your clients to download the file then delete it from their local computer, not your server.
Posted: Fri May 28, 2004 10:50 am
by glennn3
Joe wrote:Why would someone want to download a file and then delete so others cannot download it for themselves. Something sounds wrong here dude!
*edit* Wooo everyone I changed my avatar for once...
what sounds wrong with that? are you smoking something?
it's a private folder for each client that is available just to them for periodic software updates. they only need to download it once. if it stays in the folder then it'll simply confuse them.
IT'S WHAT MY CLIENT WANTS. is that confusing..?
perhaps i'm in the wrong forum. this must be the "We'll question your real needs" forum...
Posted: Fri May 28, 2004 10:50 am
by Grim...
Perhaps you should be a little more polite.
I've already answered your question.
Posted: Fri May 28, 2004 10:52 am
by glennn3
Grim... wrote:Glenn - no need to be like that - your first post was worded so it read like you wanted your clients to download the file then delete it from their local computer, not your server.
i apologize - you're right - i had just read the inane post following yours and couldn't understand why my needs are being questioned. i see the confusion in my original post - yes, it needs to be dleted from the remote dir once downloaded.
sorry...

)
Posted: Fri May 28, 2004 10:54 am
by glennn3
Grim... wrote:Perhaps you should be a little more polite.
I've already answered your question.
i was apologizing to you - Joe's post was the ridiculous one - but i was writing that before you gave me the chance to read your follow up.
Posted: Fri May 28, 2004 10:55 am
by Grim...
Anyway, IMO you're going about this the wrong way.
Why not use a database to hold information about the current version for each client, along with the appropriate links?
That way a flag could be set when the client click the download link, and a cron job at the end of each day could delete the files (as long as a good amount of time has passed since the client clicked the link).
Posted: Fri May 28, 2004 10:58 am
by magicrobotmonkey
Dang, guy, you need to relax. I was trying to figure out just exactly what you where trying to do. Your poor use of English led me to interpret your cryptic post as you trying to use php to delete a file from the clients machine. In the future, you would do better to gently correct someone who is trying to help you.
Posted: Fri May 28, 2004 11:00 am
by Grim...
Glenn: Your post was hardly verbose, was it?
glennn3 wrote:perhaps i'm in the wrong forum. this must be the "We'll question your real needs" forum...
And out of interest, yes - you did post in the wrong forum.
This thread should be in the
PHP - Code section.
Posted: Fri May 28, 2004 11:03 am
by patrikG
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.
Posted: Fri May 28, 2004 11:04 am
by glennn3
thanks for your time - here's what this is :
some financial apps for car dealers that my client wrote in some archaic code that requires a new exe to simply update data. VERY small files. when they login they're taken to their own directory where the necessary update has been placed by my client. he wants the update to dissapear, right after they download it so that they're not confused (these are car salesmen, not PC users...) - the simple website and script i built in a day for 300 dollars and i think implementing a db would be a little overkill.
i had put in a unlink() scipt to be called by the user but he doesn't even truat the salesmen to do two more steps (clicking a second file) so he wants me to make the file go away when they download it.
i know, it sounds stupid, but he's my client.
there's got to be a way to download a file in php and then run an unlink() in the same function... ? unreliable...?
thanks again