博主自己需要用到远程上传图片,在CURL中加@符号curl就会把它当成是文件上传处理, 而且文件必须是完整地址。比如图片, 可是在一些浏览器中比如火狐,$_FILES['file']['name']只有图片名称,当然可以用JS解决,但是火狐中还是无法获取到完整路径, 博主自己找到了解决办法:如下
$data = array('card1'=>'@'. $_FILES['card1']['tmp_name'], '<span style="font-family: Arial, Helvetica, sans-serif;">card2</span><span style="font-family: Arial, Helvetica, sans-serif;">' => '@'. $_FILES['card2']['tmp_name'], 'card3' => '@'. $_FILES['card3']['tmp_name'] );</span>
$data['card1_name'] = $_FILES['card1']['name']; // 把图片的名称以 POST 参数方式传递
$data['card2_name'] = $_FILES['card2']['name'];
$data['card3_name'] = $_FILES['card3']['name'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); // $url 远程上传地址
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // $data post参数
$result = curl_exec($curl);
curl_close($curl);
if($_FILES['card1'] && !empty($_FILES['card1']['name']))
{
$_FILES['card1']['name'] = $_POST['card1_name']; // 把POST传递过来的图片名称赋值给文件的文件名称
$file = $upload->uploadFile($_FILES['card1']); // 保存文件
$file = (array)json_decode($file);
if($file['status'] > 1)
{
exit(json_encode($file));
}
else
{
$card1 = $file['file'];
}
}