php - Can't upload image using curl -


i want upload images server server php curl. tested script on localhost works on server not working.

here steps:

first step

i upload image server. path of image "imgs/myimage.jpg"

second step

i excute code upload image server server.

$file_name_with_full_path = realpath("imgs/myimage.jpg"); $postdata = 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 second server.

print_r($_files["myfile"]); 

i tested code on localhost works. on server not working , display error.

notice: undefined index: myfile in .... 

i try full path of image on server command

echo realpath("imgs/myimage.jpg"); 

it shows this:

@/home/admin/domains/mydomain.com/public_html/member/imgs/myimage.jpg 

i'm not sure permission? have set file permissions 777.

what should fix problem?

i'm trying find solution entire day, not successful.

update

i apply code test on server. worked. try full path of image on server command

echo realpath("imgs/myimage.jpg"); 

it shows this:

@/var/www/vhosts/myuser/mydomain.com/imgs/myimage.jpg 

i think config server. should set up?

not sure if updated code posting here $postdata never set before. in 2nd line, have $postimg = array('myfile'=>'@'.$file_name_with_full_path); , later curl_setopt($ch, curlopt_postfields,$postdata); please use correct variable ($postimg) , should go. wondering how worked on local :)


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

android - Pass an Serializable object in AIDL -