PHP-filesize()返回一个空字符串 [英] PHP - filesize() returns an empty string

查看:212
本文介绍了PHP-filesize()返回一个空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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.

当我执行以下操作

$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

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

What is the correct way to load this file ?

推荐答案

fopen的引用PHP手册中的模式应该是读或写.您正在使用未定义模式rb.尝试使用此

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");

这篇关于PHP-filesize()返回一个空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆