kuwala Posted August 25, 2009 Share Posted August 25, 2009 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"; ?> Quote Link to comment Share on other sites More sharing options...
Alex Posted August 25, 2009 Share Posted August 25, 2009 Next time use or [code=php:0] tags. You might also want to look into [url=http://php.net/copy]copy() [/code] Quote Link to comment Share on other sites More sharing options...
kuwala Posted August 25, 2009 Author Share Posted August 25, 2009 Okay sorry my first. Um It seems to work with the copy function. But I don't understand why it doesn't work with the code I tried. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted August 25, 2009 Share Posted August 25, 2009 The video is around 20mbs I'd assume? Change your max execution time to 200 seconds and see if it does this again, but here's an example youtube php downloaders source code you could look into.... http://www.sizlopedia.com/wp-content/uploads/files/youtube-download.txt etc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.