在PHP中删除文件

QAH*_*QAH 3 php exe

我有一个php脚本,它提供了一个指向使用该脚本创建的临时文件的链接.我希望该人能够下载该文件,但我不希望该文件长时间保留在服务器上.我想删除文件说也许2分钟后.如何才能做到这一点?

ins*_* me 8

您可以在下载后立即将其删除.输出文件的内容,然后关闭unlink它.

编辑:示例

$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);
Run Code Online (Sandbox Code Playgroud)