Welcome Guest, Not a member yet? Register   Sign In
Delete file after download
#1

(This post was last modified: 05-28-2021, 02:28 PM by MatheusCastro.)

I have a situation that should download and delete the file. Is there any possibility?

I'm using this function in response:
PHP Code:
return $response->download($name$data); 

Anything like that, for example:
PHP Code:
// Other framework
return response()->download($filePath$fileName$headers)->deleteFileAfterSend(true); 

This is the bad solution?

PHP Code:
Controller:

// Set header content disposition file
header("Content-Disposition: attachment; filename=" $fileName);

// Force download writer to output
$writer->save('php://output');

// Remove file after download
unset($filePath);

// Break request to not corrupt the file
exit(); 

Im using PHP Spreedsheet library.
Reply
#2

To delete a file you use unlink(path/filename);
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(05-28-2021, 02:35 AM)InsiteFX Wrote: To delete a file you use unlink(path/filename);

Yes, okay! But the main question is whether there is any way to use the download with the response and delete it afterwards? Or if the solution would be the way I posted below not to use response->download.
Reply
#4

This may help not sure.
CodeIgniter 4 User Guide - Uploaded Files
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

You can trigger a delete function via jquery / ajax when you click the download button.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB