Delete file after time in PHP

I have a php script that provides a link to a temporary file created using a script. I want the person to be able to upload the file, but I do not want the file to remain on the server for a long time. I would like to delete the file in, say, 2 minutes. How can I do that?

+3
source share
2 answers

You can delete it immediately after downloading. print the contents of the file, then close it and unlink.

Edit : example

$fo = fopen($f, 'rb') ;
    $content = fread($fo, filesize($f)) ;
    fclose($fo) ;
}
// Stream the file to the client 
header("Content-Type: application/octet-stream"); 
header("Content-Length: " . strlen($archive)); 
header("Content-Disposition: attachment; filename=\"myfile.exe\""); 
echo $archive;
unlink($f);
+8
source

cron script . filemtime(), , , , " ".

+2

Source: https://habr.com/ru/post/1714138/


All Articles