içerik uzunluğu başlığı dönen değil curl

2 Cevap php

Kıvırmak ama içerik uzunluğu başlığını kullanarak dosya boyutunu almaya çalışırken iade edilmez:

$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 ($ gövde):

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

Bu olsa ssh ile çalışır:

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

2 Cevap

Ile-i komut satırı bir GET isteği ise CURLOPT_NOBODY bir HEAD isteği yapar ...

Eğer komut satırı sürümü ile-I kullanmak istiyorsanız daha benzer olacaktır.

Giriş curl_getinfo() ,

$size = curl_getinfo($fp, CURLINFO_CONTENT_LENGTH_DOWNLOAD);

Sonra yürütün curl_exec().

One other option is to set CURLOPT_HEADER false ve sadece do strlen($body) -- ignore this, I didn't noticed you were using CURLOPT_NOBODY.