2010-05-02 95 views
2

試圖讓圖像文件大小不返回:捲曲沒有返回內容長度標題

$url ="http://www.collegefashion.net/wp-content/plugins/feed-comments-number/image.php?1263"; 
$fp = curl_init(); 
curl_setopt($fp, CURLOPT_NOBODY, true); 
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($fp, CURLOPT_FAILONERROR,1); 
curl_setopt($fp, CURLOPT_REFERER,''); 
curl_setopt($fp, CURLOPT_URL, $url); 
curl_setopt($fp, CURLOPT_HEADER,1); 
curl_setopt($fp, CURLOPT_USERAGENT,'Mozilla/5.0'); 
$body = curl_exec($fp); 

的var_dump($體):

HTTP/1.1 200 OK 
Date: Sun, 02 May 2010 02:50:20 GMT 
Server: Apache/2.0.63 (CentOS) 
X-Powered-By: W3 Total Cache/0.8.5.2 
X-Pingback: http://www.collegefashion.net/xmlrpc.php 
Cache-Control: no-cache, must-revalidate 
Expires: Sat, 26 Jul 1997 05:00:00 GMT 
Content-Type: image/png 

它通過ssh工作雖然:

curl -i http://www.collegefashion.net/wp-content/plugins/feed-comments-number/image.php?1263 
HTTP/1.1 200 OK 
Date: Sun, 02 May 2010 03:38:43 GMT 
Server: Apache/2.0.63 (CentOS) 
X-Powered-By: W3 Total Cache/0.8.5.2 
X-Pingback: http://www.collegefashion.net/xmlrpc.php 
Cache-Control: no-cache, must-revalidate 
Expires: Sat, 26 Jul 1997 05:00:00 GMT 
Content-Length: 347 
Content-Type: image/png 

回答

1

CURLOPT_NOBODY使HEAD請求,同時用-i命令行是一個GET請求......

如果你 - 我用你的命令行版本,他們將有更多的類似。

+0

謝謝!就是這樣。頭部請求不會返回該服務器的內容長度。 – 2010-05-03 06:36:36

+0

只需添加:一些服務器只是拒絕HEAD請求並返回狀態碼405(即「不允許使用的方法」) – 2013-01-28 10:20:22

0

檢查curl_getinfo()

$size = curl_getinfo($fp, CURLINFO_CONTENT_LENGTH_DOWNLOAD); 

curl_exec()之後執行。其他

一種選擇是設置 CURLOPT_HEADERfalse,只是做 strlen($body) - 忽略這一點,我沒有你正在使用CURLOPT_NOBODY注意到。