views:

29

answers:

1

Hello friends,

I would like to create a youtube video gallery, and I would like to crop the thumbnail and save it to my server, I tryed with cURL but had no success, it works but it seens that youtube is blocking.

Is there any option to save the youtube thumbnail? http://i3.ytimg.com/vi/BdoQjb6K6XA/0.jpg

I would like to save the above thumbnail.

Thanks and best regar´s

A: 

You want to use file_get_contents, I believe. Something like below should work:

$image = file_get_contents('http://i3.ytimg.com/vi/BdoQjb6K6XA/0.jpg'); 
$file  = fopen('[path to save file]', 'w+'); 

fputs($file, $image); 
fclose($file); 
unset($image) 

Something like this should work though I didn't test. Also you should add some error handlers to the end of the remote statements so you can know if they failed. Just a quick example.

spinon
Thanks for your help, but I´m getting this error:Warning: file_get_contents(http://i3.ytimg.com/vi/BdoQjb6K6XA/0.jpg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
Rodrigo Ferrari
Yeah I think you might have problem with youtube blocking the request. In which case you probably should go the curl approach. Though you are going to have to set the headers in such a way that it is interpreted as a browser request instead of a code request.
spinon
No, not even cURL, it requires authentication and other stuffs, tryed zend http but not success even, I give it up.Thanks for your help.
Rodrigo Ferrari