Curl not returning content length header

Trying to get the size of an image file using curl but the content length header is not returning:

$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 ($ body):

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

      

It works via 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

      

+2


a source to share


2 answers


CURLOPT_NOBODY makes a HEAD request, while your command line with -i is a GET request ...



If you use -I with your version on the command line, they will be more similar.

+1


a source


Note : curl_getinfo()

$size = curl_getinfo($fp, CURLINFO_CONTENT_LENGTH_DOWNLOAD);

      



Execute it after curl_exec()

.

Another parameter is set CURLOPT_HEADER

to false

and just dostrlen($body)

- ignore this, I didn't notice what you were using CURLOPT_NOBODY

.

0


a source







All Articles