Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How do I download a file, then delete it?
  • When I try to run the following code, the last line never gets called because File::download exits the script. How can I delete the file after downloading?
    File::create($file_path, $file_name.$file_ext, $result);
    File::download($file);
    File::delete($file_path.$file_name.$file_ext);
            
  • HarroHarro
    Accepted Answer
    Register a shutdown event that will delete the file after the download has completed, something like:

    \Event::register('fuel-shutdown', function($data, $arg) { \File::delete($arg); }, $file);

    then call File::download().

    p.s. from the top of my hat, so if it doesn't work, add some debugging to the closure to see with which arguments it is called.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion