Problem returning a file size with PHP and Curl

0

I'm trying to return the size of a file with php and curl from an external host but when running curl download_content_length comes as -1, could anyone help me?

    
asked by anonymous 06.08.2014 / 20:23

2 answers

2

I made a simple example below using jQuery JS.

 $url = 'http://code.jquery.com/jquery-1.11.1.min.js';
 $ch = curl_init( $url );

 curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
 curl_setopt($ch, CURLOPT_HEADER, TRUE);
 curl_setopt($ch, CURLOPT_NOBODY, TRUE);

 curl_exec($ch);
 $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);

 curl_close($ch);

 echo ($size / 1024) . ' kb';

output: 93.541015625 kb

    
06.09.2014 / 01:49
-1

When using CURL there are many things that can go wrong, so I recommend that you use some component to make these requests I use Guzzle so you'll have more friendly mistakes

    
06.08.2014 / 23:21