PHP-filesize()返回一个空字符串


PHP - filesize() returns an empty string

我有一个奇怪的问题。我有一个图像,我需要上传到文件服务器。我正在使用php来做这件事。图像权限如下

-rw-r--r--. 1 apache apache  148041 Dec 22 08:25 Not.jpg

我检查了文件是否存在。我已经下载了这个文件,发现它还可以。它的原始大小是60 KB。权限也可以。

当我进行以下时

$filepath = "../uploads/".$file_name;
$image = fopen($filepath, "rb");
echo file_exists($filepath).' ';
echo filesize($filepath). 'bytes ';
echo exif_read_data($filepath). ' ';

输出为1 bytes 200

1 - File Exists
bytes - This is where the error occurs. filesize() is returning an empty string here
200 - server response

加载此文件的正确方式是什么?

作为PHP fopen手册的参考,模式应该是读或写。您正在使用未定义模式rb。尝试使用这个

$image = fopen($filepath, "r");