php - Why can't get the length of the iso file with `CURLINFO_CONTENT_LENGTH_DOWNLOAD` in php_curl? -


this question has answer here:

i want length of iso file on 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 -1 code,how length of iso file php_curl?
answer of leggendario , key of problem set curlopt_followlocation right answer.
makes question different http://stackoverflow.com/questions/2602612/php-remote-file-size-without-downloading-file.

from documentation

curlinfo_content_length_download

pass pointer double receive content-length of download. value read content-length: field. since 7.19.4, returns -1 if size isn't known.

you must first execute curl:

curl_exec($curl);  $size = curl_getinfo($curl, curlinfo_content_length_download); echo $size;  curl_close($curl); 

but careful because http://cdimage.debian.org/debian-cd/8.0.0/i386/iso-cd/debian-8.0.0-i386-lxde-cd-1.iso redirection http://gensho.acc.umu.se/debian-cd/8.0.0/i386/iso-cd/debian-8.0.0-i386-lxde-cd-1.iso. may want set curlopt_followlocation true.

curl_setopt($curl, curlopt_followlocation, 1); 

otherwise size of page of redirect.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -