ocr_a Posted March 10, 2015 Share Posted March 10, 2015 Hello, as mentioned here: https://processwire.com/talk/topic/296-programmed-page-creation-import-image-from-url/?p=2016 i want to grab an image and save it on my server (for editing it later). so here is my php. it's pretty easy, pt_embed_youtube is the video ID for a youtube video and i want to use it to grab the videos thumbnail and save it. pt_embed_youtube_pixel is an empty image field, which allows only 1 image. echo the content id is to make sure i am on the right page (this works fine). if($content->pt_embed_youtube){ echo $content->id; if(!$content->pt_embed_youtube_pixel){ $content->of(false); $content->pt_embed_youtube_pixel = "http://img.youtube.com/vi/{$content->pt_embed_youtube}/1.jpg"; $content->save(); } echo "<img src='{$content->pt_embed_youtube_pixel->url}' alt=''>"; } but i get this error and i really donot know what to do with it. is my server misconfigured, or did i miss some code or mixed it up? Error: Exception: Unable to copy: http://img.youtube.com/vi/QxWbOZjxkA4/1.jpg => /kunden/238982_5020/webseiten/club/dev/site/assets/files/1030/1.jpg (in /kunden/238982_5020/webseiten/club/dev/wire/core/Pagefile.php line 107) #0 /kunden/238982_5020/webseiten/club/dev/wire/core/Pageimage.php(630): Pagefile->___install('http://img.yout...') #1 [internal function]: Pageimage->___install('http://img.yout...') #2 /kunden/238982_5020/webseiten/club/dev/wire/core/Wire.php(389): call_user_func_array(Array, Array) #3 /kunden/238982_5020/webseiten/club/dev/wire/core/Wire.php(344): Wire->runHooks('install', Array) #4 /kunden/238982_5020/webseiten/club/dev/wire/core/Pagefile.php(73): Wire->__call('install', Array) #5 /kunden/238982_5020/webseiten/club/dev/wire/core/Pagefile.php(73): Pageimage->install('http://img.yout...') #6 /kunden/238982_5020/webseiten/club/dev/wire/core/Pagefile.php(48): Pagefile->setFilename('http://img.yout...') #7 /kunden/238982_5020/webseiten/club/dev/wire/core/Pageimage.php(74): Pagefile->__construct(O This error message was shown because you are logged in as a Superuser. Error has been logged. thanks for any help and or hints! Link to comment Share on other sites More sharing options...
BitPoet Posted March 10, 2015 Share Posted March 10, 2015 Looks like allow_url_fopen is disabled in your server's php settings, preventing file functions like copy or file_get_contents from working on URLs. If you can't change that setting, you could download the file manually into a temporary folder using curl and then assign the local path to the temp file (making sure the directory in $config->paths->tmp actually exists beforehand). A quick&dirty take: // ... $localPath = download_file($content->pt_embed_youtube, $config->paths->tmp); $content->pt_embed_youtube_pixel = $localPath; // ... function download_file($url, $tempdir) { $fp = $tempdir . basename(parse_url($url, PHP_URL_PATH)); $fh = fopen($fp, 'wb'); $curl = curl_init($url); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_FILE, $fh); curl_exec($curl); curl_close($curl); fclose($fh); return $fp; } 1 Link to comment Share on other sites More sharing options...
adrian Posted March 10, 2015 Share Posted March 10, 2015 Assuming BitPoet is correct and that is your problem, then it should work after that. Nothing wrong with doing it manually obviously, but just an FYI - there is a module for grabbing video images from YouTube/Vimeo and populating an images field, along with descriptions: https://processwire.com/talk/topic/4614-youtube-and-vimeo-thumbnail-grabber/ 1 Link to comment Share on other sites More sharing options...
ocr_a Posted March 10, 2015 Author Share Posted March 10, 2015 thanks both, it was the allow_url_fopen which was set to 0 instead of 1. would be nice to have something like this (the php.ini settings connected to the api) in the documentary?! anyways, thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now