我尝试通过$_FILES
发送curl
:
$post = array('files' => $_FILES);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://test.com/upload_page');
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec ($ch);
curl_close($ch);
但我注意到行curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
:
注意:数组转换为字符串
我知道$post
应该是字符串,但它是如何为$_FILES
做的?
答案 0 :(得分:1)
以下是使用php
卷曲上传图片的代码$file_name_with_full_path = realpath('./sample.jpeg');
$post = array('extra_info' => '123456','file_contents'=>'@'.$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, $post);
$result=curl_exec ($ch);
curl_close ($ch);