I want to upload images from my Server to another Server with php curl. I tested my script on localhost it works but on server it not working.
Here are my steps:
First step
I upload an image to my server. Path of the image is "imgs/myimage.jpg"
Second step
I excute this code for upload image from my server to another server.
$file_name_with_full_path = realpath("imgs/myimage.jpg");
$postimg = array('myfile'=>'@'.$file_name_with_full_path);
$headers = array("Content-Type:multipart/form-data");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, "http://www.secondserver.com/image.php");
$data = curl_exec($ch);
curl_close($ch);
This code in image.php from second server.
print_r($_FILES["myfile"]);
I tested this code on localhost it works. But on Server it not working and display error.
Notice: Undefined index: myfile in ....
I try to get full path of the image on the server with command
echo realpath("imgs/myimage.jpg");
It shows this:
@/home/admin/domains/mydomain.com/public_html/member/imgs/myimage.jpg
I’m not sure what it is about Permission? But I have also set up file permissions are 777.
What should I do to fix this problem?
I’m trying to find a solution for the entire day, but was not successful.