Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Thanked 0 Times in 0 Posts

    download AND delete a file from the server

    i'm providing downloadable executables for several particularly ignorant clients who i cannot trust to be able to delete the file from their folder 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 from the remote directory...

    it's a very inexpensive website, don't want to mess with a database ... just a simple download script that might include an unlink() function...?

    thanks so much,

  • #2
    Super Moderator
    Join Date
    May 2002
    Perth Australia
    Thanked 101 Times in 99 Posts
    you can create a page that handles the download and unlinks the file easily enough ...

    PHP Code:
    /*you may need to set the right headers for the file type*/
    //header("Content-type: application/force-download");
    BUT , what if the client does not complete the download , or if on occaision you have a corrupt download ?

    you can count bytes using fopen,fread,fputs etc but that does still not proove that the downloaded file actualy made it in one piece.

    I had to do something similar once & the end result was to mark a file as 'downloaded' in a database (or flatfile/whatever) then run a timed cron job to delete all such files if the transaction was $x hours old, the logic being that if they had not actually downloaded the file is $x hours then it was their problem, far from perfect.

    We could not find a way to validate that the file had actually downloaded and was in good shape, other than relying on the user to confirm such. (short of having control of the users machine and running a script to check such)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts