使用filesize读取远程文件大小 [英] Reading remote file size using filesize
问题描述
我阅读了 filesize()能够计算文件的手册远程文件的大小.
但是,当我尝试使用下面的代码段进行操作时.我收到错误PHP Warning: filesize(): stat failed for http://someserver/free_wallpaper/jpg/0000122_480_320.jpg in /tmp/test.php on line 5
这是我的摘录:
$file = "http://someserver/free_wallpaper/jpg/0000122_480_320.jpg";
echo filesize( $file );
结果是,我不能将HTTP用于 文件大小().结案.我会用 摘录此处作为解决方法 解决方案.
I read the manual that filesize() is able to calculate file size from remote file.
However, when I try to do that with snippet below. I got error Here's my snippet:
Turns out, I can't use HTTP for
filesize(). Case close. I'll use
snippet here as a work-around
solution.
The PHP man page for filesize says: This doesn't mean every protocol/wrapper works "out of the box" with 这篇关于使用filesize读取远程文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!filesize
不适用于HTTP-它取决于stat
,该stat
PHP Warning: filesize(): stat failed for http://someserver/free_wallpaper/jpg/0000122_480_320.jpg in /tmp/test.php on line 5
$file = "http://someserver/free_wallpaper/jpg/0000122_480_320.jpg";
echo filesize( $file );
filesize
doesn't work for HTTP - it depends on stat
, which isn't supported for the HTTP(S) protocol.Refer to List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality.
filesize
. You could always get around that by doing a full GET of the remote URL and calculating the size of the data you get back, of if you can get a Content-Length header you could try a HEAD request to avoid transferring the file data.