• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete file after download

#1
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?
Reply

#2
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.
Reply

#3
(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
Reply

#4
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 )
Reply

#5
(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); 
Reply

#6
(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
Reply

#7
(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?
Reply

#8
I found problem
There is exit command in end of force download function :|
Reply

#9
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.
Reply

#10
(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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.