Delete file after download |
Hi guys
I have script file that user upload file to server with this script After upload file,i update data in user's file and again send this file to user I use force download from codeigniter helper ooom i need after download file via user,the file delete from server Maybe?
Hosting usually only gives each site limited harddrive resources, so yes, it's good idea to delete any user files that are not needed anymore.
Check out unlink function for PHP.
(07-10-2018, 01:14 AM)Pertti Wrote: Hosting usually only gives each site limited harddrive resources, so yes, it's good idea to delete any user files that are not needed anymore. I used unlink but not working I try use ignore_user_abort(true); but file not deleting
Check you folder and file permissions on them.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(07-10-2018, 01:26 AM)omid_student Wrote: I used unlink but not working If file uploads, user can't really abort your PHP script executing. Once they access URL through their browser, even if they close the browser, the script will still finish what it's doing. I'd check that you are trying to delete the right file. Enable error messages and echo out some of your variables to check that it does actually hold data that you expect to be there. PHP Code: $file = 'path/to/file.txt';
(07-10-2018, 04:25 AM)Pertti Wrote:(07-10-2018, 01:26 AM)omid_student Wrote: I used unlink but not working Can i read file content to variable and delete file and echo content?
Aha, yeah, that'd be it, well done.
I suppose in most cases it would make sense there is no additional output once you send the file, because that would end up in the end of the file on users harddrive. You only need couple of header() calls to make browser download the file, so you can write your own version of force download function, or alternatively you could write cron job that goes and cleans files off once their old enough to def not be in use anymore. (07-10-2018, 05:05 AM)omid_student Wrote: Can i read file content to variable and delete file and echo content? Depends on the file size, but technically, yeah. If the file is small, like few meg, could be a reasonable option. Might actually be even better, because when you modify original file, you've already load it in memory. |
Welcome Guest, Not a member yet? Register Sign In |