PHP - filesize() returns an empty string

*爱你&永不变心* 提交于 2019-12-24 00:44:09

问题


I have a strange problem. I have an image which i need to upload to a file server. I 'm using php to do this. The image permissions are the following

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

I checked that the file exists. I have downloaded the file and found it to be ok. it's original size is 60 KB. Permissions are also fine.

When I do the following

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

The output is 1 bytes 200

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

What is the correct way to load this file ?


回答1:


As reference to fopen manual of PHP the modes should be either read or write. You are using undefined mode rb. try using this

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


来源:https://stackoverflow.com/questions/34429373/php-filesize-returns-an-empty-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!