我想在php中使用filesize
,但如果不能为我工作。我该怎么办?
$img = 'http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg';
echo filesize($img);
错误:
filesize():stat失败了 http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg
答案 0 :(得分:2)
filesize()仅适用于您的本地文件。你有两个选择:
功能:
$file = get_headers("http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg", TRUE);
echo $file['Content-Length'];
给予:69322
属于你的
此外,您还可以从get_headers中检索以下详细信息:
Array
(
[0] => HTTP/1.1 200 OK
[Date] => Wed, 18 May 2016 09:55:10 GMT
[Server] => Apache
[Last-Modified] => Fri, 29 Apr 2016 16:00:34 GMT
[Accept-Ranges] => bytes
[Content-Length] => 69322
[Connection] => close
[Content-Type] => image/jpeg
)
答案 1 :(得分:1)
您是否正在寻找:Easiest way to grab filesize of remote file in PHP?
$img = "http://grdagrd.com/uploads/3ac9ac4d9d69ef18785876438bb0a69a.jpg";
$head = array_change_key_case(get_headers($img, TRUE));
echo $filesize = $head['content-length']; //69322
OR
echo strlen(file_get_contents($img)); //69322