I want to get the length of the iso file on the web
http://cdimage.debian.org/debian-cd/8.0.0/i386/iso-cd/debian-8.0.0-i386-lxde-CD-1.iso
<?php
$szUrl = 'http://cdimage.debian.org/debian-cd/8.0.0/i386/iso-cd/debian-8.0.0-i386-lxde-CD-1.iso';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $szUrl);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_NOBODY, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$size = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
echo $size;
?>
The output is -1 with the code,How to get the length of the iso file properly with php_curl?
With the answer of Leggendario , the key of my problem is to set
CURLOPT_FOLLOWLOCATION to get right answer.
It makes my question different from the http://stackoverflow.com/questions/2602612/php-remote-file-size-without-downloading-file
.