0

I am new to php, can anyone tell me how to send an image file from one server to the other server using cURL in php

My Local host code is:

$sourceurl = "//localhost:8080...../example.jpg";

function writefile($sourceurl, NewImageName.jpg){

    $fp = fopen ($image_file, 'w+');              

    $ch = curl_init($image_url);    
    curl_setopt($ch, CURLOPT_FILE, $fp);          
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1000);          
    curl_exec($ch);
    curl_close($ch);                              
    fclose($fp);                                    
}

The above code is working fine and created the image file within this page directory, where as I need to change the directory locally (like to desktop) or other SERVER directory to create the image file.

Ram Anand
  • 1
  • 1
  • I didnt get you, I need to change the url path of the image file the above code creates thats it. – Ram Anand May 25 '15 at 13:52
  • normally you do not have write access of external server, so you can't use fopen to "send" file. Instead, you need to run this piece of code at the destination server, and "get" the file from the original server. However if the destination server is open for upload, you could use HTTP POST to send the file to it, but not with fopen. – Jacky Cheng May 25 '15 at 13:57

0 Answers0