Jump to content

Saving a file from URL


kuwala

Recommended Posts

Ive been trying to save youtube video.flv files from a url like http://www.youtube.com/get_video?video_id=2FN1jExBUhw&sk=5ZAx5CJYDkJkXVHQLBLPnl9erb295YQXC&t=vjVQa1PpcFPiR9baKBgXvqJtbhJiIH4uRIHGRPEtzEk%3D

 

But for some reason the file is always 0 bytes. when you type the url in a browser it lets you save the video.flv file. I was thinking I may need to use cURL to do this. I have tried these two methods. But all i get is a 0k file. Any tips. Thanks.

 

<?php

/*

$contents = file_get_contents('http://www.youtube.com/get_video?video_id=2FN1jExBUhw&sk=5ZAx5CJYDkJkXVHQLBLPnl9erb295YQXC&t=vjVQa1PpcFPiR9baKBgXvqJtbhJiIH4uRIHGRPEtzEk%3D');

 

$fp = fopen('uploads/video.flv', 'w');

fwrite($fp, $contents);

fclose($fp);

 

 

 

$ch = curl_init("http://www.youtube.com/get_video?video_id=2FN1jExBUhw&sk=5ZAx5CJYDkJkXVHQLBLPnl9erb295YQXC&t=vjVQa1PpcFPiR9baKBgXvqJtbhJiIH4uRIHGRPEtzEk%3D");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);

$output = curl_exec($ch);

 

$fh = fopen("uploads/video2.flv", 'w');

fwrite($fh, $output);

fclose($fh);

*/

 

 

$ch = curl_init();

/**

* Set the URL of the page or file to download.

*/

curl_setopt($ch, CURLOPT_URL,

'http://www.youtube.com/get_video?video_id=2FN1jExBUhw&sk=5ZAx5CJYDkJkXVHQLBLPnl9erb295YQXC&t=vjVQa1PpcFPiR9baKBgXvqJtbhJiIH4uRIHGRPEtzEk%3D');

/**

* Create a new file

*/

$fp = fopen('video3.flv', 'w');

/**

* Ask cURL to write the contents to a file

*/

curl_setopt($ch, CURLOPT_FILE, $fp);

/**

* Execute the cURL session

*/

curl_exec ($ch);

/**

* Close cURL session and file

*/

curl_close ($ch);

fclose($fp);

 

echo "kinnda done";

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.