How can I save a picture from another server to my server with PHP ? For example I would like to save picture http://www.google.com/intl/en_ALL/images/logo.gif to my server using a php script. How can I do it ? thank you
$source = 'http://www.google.com/intl/en_ALL/images/logo.gif'; $target = 'folder/logo.gif'; copy($source, $target); PHP: Very basic example.
Hey what is the alternative, because I'm getting: copy() [function.copy]: URL file-access is disabled in the server configuration
You could try this basic example, although i'm sure nico has some slick solution there too <?php $image_url = "http://www.google.com/intl/en_ALL/images/logo.gif"; // Grab the image data $image_data = file_get_contents($image_url); // Extract the original image name $image_name = basename($image_url); // Save the image $fp = fopen($image_name, "w"); fwrite($fp, $image_data); fclose($fp); ?> PHP: p.s. just noticed, that the problem is probably not in the copy function, but could be in using all other url open based solutions. In that case you could try using cURL.
Ok thank you. I just found a solution liste in dreamhost wiki: $ch = curl_init($source); $fp1 = fopen($target, "w"); curl_setopt($ch, CURLOPT_FILE, $fp1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp1); Thank you If you got any other alternatives I'll be glad to hear