views:

173

answers:

3

I am currently using php and ajax file upload to develop a web application. in a web application involves getting the files uploaded from user, e.g email client, photo gallery. This is the scenario that i got stuck.

When user uploads some files but close the browser without submit, i want to delete those files and only move the relevant files.

I have tried leave the stuff in tmp/ folder and been given a temp name by apache but when i do the upload i have to move the file immediately otherwise the file cannot be found in the later stage by referencing to the temp filename.

The reason that i leave it in a /tmp/ is that i will want to setup a cron job and delete files in those folder to free up server space.

Am i doing the right thing? or is there a standard industry approach used by hotmail, google etc?

A: 

Why not just move it from the tmp/ folder to your own temporary staging folder immediately, and then keep a reference to it in the DB, and have a cron job that periodically scans the DB for 'staging' files with a timestamp more than X hours in the past and removes them?

Amber
+1  A: 

You will need another temporary folder which you can manage yourself.

You can upload to this folder you created yourself called temp. When the uploading is complete, move the temporary file from PHP's tmp folder into your temp folder.

Then when the submission is done, you move the file away into its respective folders.

Have a cron job that works background to remove old files in that folder.

Remember to give permissions to PHP, Apache and the cron job for access to the folder.

Don't rely on industrial standards - besides, Microsoft and Google don't use PHP. (maybe Google, but definitely not Microsoft).

thephpdeveloper
A: 

I dont know about big boys, but I guess, you can create a database table, that will hold the temporary file names, the pros of this approach is that, you can delete the entry from temporary file table, even browser is not closed in the middle, and additionally setting up cron job to delete files as found under temporary file table.

r0ash