Get remote image file from another server saved into your server using CURL
Submitted by inder on Wed, 10/22/2008 - 16:34.
Below is the code that was used for getting image from a remote location and saving that image to current folder.This code can be modified easily to achive something different.
<?php
/**
* @desc file: This source was used for copying images from another server to our own server and can be modified according to requirements.
*/
//***********************URL of image which you need**************
$img_url='http://www.inderweb.com/inderweb/userpictures/picture-1.jpg';
$ext_arr=explode("/",$img_url);
$cnt=count($ext_arr);
//***********************name of new image you want to keep*************
$img_name=$ext_arr[($cnt-1)];
copyFile($img_url,$img_name);//Call the CURL function for getting image
/**
* @desc This function uses curl for coping a remote image file from another server to its own directory.
*/
function copyFile($img_url,$img_name)
{
$crl_ptr= curl_init( $img_url );
$file_ptr=fopen($img_name,'w');
curl_setopt( $crl_ptr, CURLOPT_FILE, $file_ptr );
curl_setopt( $crl_ptr, CURLOPT_HEADER, 0 );
curl_exec ( $crl_ptr );
$curl_info = curl_getInfo( $crl_ptr );
curl_close($crl_ptr );
fclose($file_ptr);
echo '<h2>Details of file transfer are as below:</h2><br><pre>';
print_r($curl_info);
echo '</pre>';
}
?>
| Attachment | Size |
|---|---|
| file_cpoy.php.txt | 1.17 KB |
![Validate my RSS feed [Valid RSS]](http://feedvalidator.org/images/valid-rss.png)