Login To InderWeb ! Just Play !

Username:
Password:

UserSubmittedComments

Get remote image file from another server saved into your server using CURL

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>';
}
?>
AttachmentSize
file_cpoy.php.txt1.17 KB

several URLS

Sorry please for give me as i'm no developer, just trying to great an oscomerce website for my wife. in the above code if i need to get images from different locations would the correct code be $externalurl=array("http://website1/image/image1.jpg","http://website2/image/image12.jpg",http://website3/image/image13.jpg"); then $img_url='http://www.inderweb.com/inderweb/userpictures/picture-1.jpg'; would become $img_url='$externalurl';   Thanks Rob

Popular Tags