script to download AND delete a file...
Moderator: General Moderators
script to download AND delete a file...
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
thanks so much,
gn
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
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.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?
am i certain that it's something that they need to download? are you serious?
am i in the right forum...?
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?
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?
Last edited by Grim... on Fri May 28, 2004 10:49 am, edited 1 time in total.
what sounds wrong with that? are you smoking something?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...
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...
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.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.
sorry...
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).
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).
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
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.
Glenn: Your post was hardly verbose, was it?
This thread should be in the PHP - Code section.
And out of interest, yes - you did post in the wrong forum.glennn3 wrote:perhaps i'm in the wrong forum. this must be the "We'll question your real needs" forum...
This thread should be in the PHP - Code section.
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.
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.
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
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