简体   繁体   中英

File upload and storage handling in a web application

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, eg 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?

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).

为什么不立即将它从tmp /文件夹移到您自己的临时登台文件夹,然后在数据库中保留对其的引用,并执行cron作业来定期扫描数据库以查找时间戳大于X的“登台”文件过去几个小时并将其删除?

我不知道大男孩,但是我想,您可以创建一个数据库表,该表将保存临时文件名,这种方法的优点在于,即使浏览器未关闭,您也可以从临时文件表中删除该条目。中间,并另外设置cron作业以删除在临时文件表下找到的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM