谁能帮我解决这个无意义的问题吗?
<?php
if(!readfile($path))
{
$error = error_get_last();
imageError('*'.$error['type'].','.$error['message'].','.$error['file'].','.$error['line'].'*'); // Outputs the error on an image
exit;
}
?>
这会输出一个显示“,,,”的图像 - 基本上错误是空的。 我认为这个问题可能与我试图在同一时刻读取同一个文件 10 次有关。我有这样的东西:
<img src="images/10/seo-friendly.jpg" />
<img src="images/10/seo-friendly2.jpg" />
<img src="images/10/seo-friendly3.jpg" />
<img src="images/10/seo-friendly4.jpg" />
<img src="images/10/seo-friendly5.jpg" />
<img src="images/10/seo-friendly6.jpg" />
<img src="images/10/seo-friendly7.jpg" />
<img src="images/10/seo-friendly8.jpg" />
<img src="images/10/seo-friendly9.jpg" />
<img src="images/10/seo-friendly10.jpg" />
然后我的 .htaccess 中有一个重写规则,例如:
RewriteRule images/([0-9]+)/.*\.(png|jpg|gif) resize.php?id=$1 [L]
所以,发生的情况是我基本上在同一时刻请求同一个文件 10 次。大多数时候它工作正常,但有时我会遇到这个问题(仅针对 10 个图像中的 1-3 个)。
非常感谢任何线索。
谢谢。
最佳答案
readfile()
返回从文件中读取的字节数。因此,您尝试读取的文件完全有可能是空的并且没有发生错误。
如果确实有错误,您可以使用 set_error_handler()
捕获错误并根据需要进行处理。
关于PHP readfile 失败但没有给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8024077/