简体   繁体   中英

send image with curl

PHP

$filename=time().'.png';
$addressImage="/mahyapardaz/chap/tmp/".$filename;
$domain = $_SERVER['HTTP_HOST'];
$prefix = 'http://';
$relative = '/mahyapardaz/viewer/add_pic.php';
$target_url =$prefix.$domain.$relative ;         
$file_name_with_full_path = realpath($addressImage);   
$fields = array(
                'code' => $code,
                'iddarkh        'insertdaste' =>  ($BPM_MahaleNameDarArchive["Daste"]),
                'insertnoe' =>  ($BPM_MahaleNameDarArchive["Noe"]),
                'codeMeli' =>  (''),
                'shemareSafhe' =>  ('1'),
                'newVersion' =>  (''),
                'image' =>  '@'.$file_name_with_full_path,
                );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

when set @ for field name image curl does not worked and does not call the app_pic but when remove '@' from image this work well? why? perhaps realpath is not correct!? and var_dump($result) equals to null.

1.check for file exsited

if (file_exists($file_name_with_full_path)) {
    echo "The file $file_name_with_full_path exists";
} else {
    echo "The file $file_name_with_full_path does not exist";
}

2.

$file_name_with_full_path = realpath('.').'\\tmp\\'.$filename; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM