0
我想用php cURL上传图片。但有些事情是错误的。cURL文件上传问题
这是后数据
-----------------------------192153227918513
Content-Disposition: form-data; name="resimbaslik"
CCClient
-----------------------------192153227918513
Content-Disposition: form-data; name="imgfile"; filename="clinteastwoodo.jpg"
Content-Type: image/jpeg
,我试图上传我的照片与此PHP代码
$postfields = array();
$postfields ["resimbaslik"] = "CCClient";
$postfields ["imgfile"] = "filename=\"clinteastwoodo.jpg\"";
$referer = "http://www.example.com/ex1.php";
curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/example.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_REFERER, $referer);
$result = curl_exec ($ch);
而且它给我417 - Expectation Failed
错误。 图片与我的.php文件在同一个目录中。
有人可以帮我解决它吗?
谢谢。
No not Lighttp。它无法解决我的问题。我之前尝试过。我该如何使用这个帖子的标题? –
$ postfields [“imgfile”] =“文件名= \”clinteastwoodo.jpg \“”; 没有@用于文件上传的字段?另外,$ postfield ['imgfile']将是表单中的字段名,所以“filename =没有意义。 – erm3nda