php curl super long url malformed

thevoipman picture thevoipman · Mar 23, 2013 · Viewed 8.7k times · Source

I have a long url nested in a variable: $mp4, and trying to download it with curl but i'm getting malformed error. Please help me if you can, thank you in advance!

The below is what I have in my php script:

exec("curl -o $fnctid.mp4 \"$mp4\"");

Error message:

curl: (3) <url> malformed

Sample url to test download:

http://f26.stream.nixcdn.com/6f4df1d8c248cf149b846c24d32f1c35/514e0209/PreNCT5/22-TaylorSwift-2426783.mp4

Answer

Baba picture Baba · Mar 26, 2013

The current url is returning 408 - Request Timeout if that is fixed you are you this simple code :

$url = 'http://f26.stream.nixcdn.com/6f4df1d8c248cf149b846c24d32f1c35/514e0209/PreNCT5/22-TaylorSwift-2426783.mp4';
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';


$file = __DIR__ . DIRECTORY_SEPARATOR . basename($url);
$fp = fopen($file, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 320);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
echo curl_exec($ch);

var_dump(curl_getinfo($ch));   // return request information 


curl_close($ch);
fclose($fp);