CodeIgniter Forums

Full Version: Delete file after download
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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.

Check out unlink function for PHP.

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.
(07-10-2018, 01:26 AM)omid_student Wrote: [ -> ]I used unlink but not working
I try use ignore_user_abort(true); but file not deleting

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';

// ...

error_reporting(E_ALL);
echo 
$file;
unlink($file); 
(07-10-2018, 03:27 AM)InsiteFX Wrote: [ -> ]Check you folder and file permissions on them.

It is 0777 permisson
I think after force download,other command dont execute
(07-10-2018, 04:25 AM)Pertti Wrote: [ -> ]
(07-10-2018, 01:26 AM)omid_student Wrote: [ -> ]I used unlink but not working
I try use ignore_user_abort(true); but file not deleting

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';

// ...

error_reporting(E_ALL);
echo 
$file;
unlink($file); 

Can i read file content to variable and delete file and echo content?
I found problem
There is exit command in end of force download function :|
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.
Pages: 1 2