我试图在第一次显示后从服务器删除图片(.jpg)。
但文件在显示之前就被删除了(unlink();)。我已经尝试过 sleep() 但这只会延迟加载,并且在显示之前删除所有文件。
您可以使用 mod_rewrite 将 jpg 请求重定向到脚本,该脚本将图像加载到内存中,删除文件,然后提供图像。 IMO,这是最简单、最容易的解决方案。下面的不安全示例...
.htaccess 文件示例:
# Turn on URL rewriting
RewriteEngine On
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
索引.php
<?php
$image_file = $_SERVER['PATH_INFO'];
// clean data, strip current/parent directory to block transversal, etc...
if (file_exists('images/' . $image_file))
{
$image_data = file_get_contents('images/' . $image_file);
// determine image mimetype using phps mimetype functions
unlink('images/' . $image_file);
header('Content-Type: image/jpeg');
echo $image_data;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)