PHP readfile 失败但没有给出错误

标签 php readfile

谁能帮我解决这个无意义的问题吗?

<?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/

相关文章:

php - 从 MySQL 检索字符串

php - 数据库内容将自己设置为 0

php - PDO返回了不正确但重复的数据。 key 不在数据库中。

c++ - Windows Readfile 返回 ERROR_INVALID_PARAMETER 87

java - 如何在没有数组的情况下使用 Java 中的 txt 文件阅读器来生成随机短语生成器

php - 具有预定义值的 php 类出错?

php - 试图了解 array_diff_uassoc 优化

python - 如何从python文件中读取特定数量的 float ?

PHP readfile/fgets/fread 导致对服务器的多次请求

python - 如何在python中读取大型压缩文件而不将其全部加载到内存中