gpt4 book ai didi

php - 在 PHP 中一段时间​​后删除文件

转载 作者:可可西里 更新时间:2023-11-01 00:07:52 27 4
gpt4 key购买 nike

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

最佳答案

您可以在下载后立即将其删除。输出文件的内容,然后关闭它并取消链接它。

编辑:例子

$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);

关于php - 在 PHP 中一段时间​​后删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1217636/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com