Jump to content

Code to auto-delete a file that's been uploaded?


tycoonbob

Recommended Posts

Hello all.  In lack of better terms, I am a programming noobie when it comes to designing code.  I can look at a code and figure it out, but basically I am trying to figure this out.  I host a website from home, running on a server 2008 machine, with apache/php, basically to share files from home, work, friends house, wherever I need.  I do have a FTP for this, but I also want to be able to upload files via http.  I actually want to be able to set a time or date that the file will auto-delete.  Such as, I select a file from my local machine, set the deletion time to 1 hour/60 minutes/3600 seconds, whatever, upload it to the site, and it spit back a url that I can access that file for that set amount of time.  It would be great to implement something like bit.ly to shorten the link, or even something to randomize the link.  Any ideas on that from anyone?  Willing to donate (paypal) a little bit if someone can actually help me out, or point me in the right direction.  A week on google has proved useless. 

Thanks so much.

Link to comment
Share on other sites

If I were you, I would create a database with an id,filename,endtime

From there you could have a page that takes in a get variable such as mysite.com/getfile.php?id=4

This page would then check the database endtime for that id against the current date, delete the file if necessary and spit back an error, or show the file because it is still in the timeframe. Basically nothing would be done automatically,  but everytime someone tries to access the page, it does the check so it appears as though it was deleted at its expiration time.

 

another option would be to check every single file/delete them in the entire database per every page request, so it would most likely be a little more up to date.

 

Hope this plants an idea, let me know what you think.

Link to comment
Share on other sites

The process would look something like this in chronological order:

 

go to upload site

upload file

store id,filename,expiredate in database

spit back download page with ?id=# from the file just uploaded

 

go to download.php?id=#

page performs check for expiration, deletes if necessary, or spits out the file

 

optional: delete database record AND file on expiration

optional: check/delete all files regardless of incoming ID every page load, slower, but files stay more up to date

 

^^this is a more simple option

 

 

And like matthew said, you could use something like 'cron' to automatically do it reguardless of people visiting your page. But thats up to you.

Link to comment
Share on other sites

Yes, that idea sounds great.  I figured some kind of db could be used.  My experience in SQL is as much as in php/xml.  I can create users/databases, and set permissions from the CLI.  Would it be possible to find a guide to doing something like this, or have a nice little write up?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.