用curl发送图像

时间:2014-11-26 11:31:21

标签: php curl directory

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);

为字段名@设置image时curl不起作用且不会调用app_pic但是当从image删除'@'时这项工作正常吗? 为什么? 也许realpath不正确!? 并且var_dump($result)等于null。

1 个答案:

答案 0 :(得分:0)

1.检查文件是否存在

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;