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?
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?
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
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