通过PHP中的CURL获取图像大小
发布时间:2020-12-13 22:48:54 所属栏目:PHP教程 来源:网络整理
导读:参见英文答案 Remote file size without downloading file????????????????????????????????????13个 我正在使用此代码在PHP中获取图像大小,它正在为我完美工作. $img = get_headers("http://ultoo.com/img_single.php",1);$size = $img["Content-Length"];e
参见英文答案 >
Remote file size without downloading file????????????????????????????????????13个
我正在使用此代码在PHP中获取图像大小,它正在为我完美工作. $img = get_headers("http://ultoo.com/img_single.php",1); $size = $img["Content-Length"]; echo $size; 但是如何通过CURL获得这个? $url = 'http://ultoo.com/img_single.php'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,1); curl_setopt($ch,CURLOPT_HTTPHEADER,"Content-Length" ); //curl_setopt($ch,CURLOPT_NOBODY,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); $filesize = $result["Content-Length"]; curl_close($ch); echo $filesize; 解决方法
设置curl_setopt($ch,true);然后print_r($result),你会看到像
HTTP/1.1 200 OK Date: Tue,04 Jun 2013 03:12:38 GMT Server: Apache/2.2.15 (Red Hat) X-Powered-By: PHP/5.3.3 Set-Cookie: PHPSESSID=rtd17m2uig3liu63ftlobcf195; path=/ Expires: Thu,19 Nov 1981 08:52:00 GMT Cache-Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0 Pragma: no-cache Content-Length: 211 Content-Type: image/png 我不认为Content-Length是获得图像大小的正确方法,因为我在curl和get_header之间得到了不同的结果 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |