我正在尝试使用php将文件上传到允许通过表单上传文件的网站。当我尝试运行代码时,出现“错误请求(无效数字)”错误。然后当我使用CURLOPT_FAILONERROR
启用cURL失败时出错,我收到“400错误”。我想我已经正确输入了所有内容,我已经从同一个网站上下载了类似的文件。
$Submitted_ImportFile = realpath($Submitted_ImportFile);
$postdata = array(
'NOSAVE___Form_Submission_Token' => $NOSAVE___Form_Submission_Token,
'import_type' => $import_type,
'span_Customers_BillingAddresses' => $Customers_BillingAddresses,
'span_Customers_ShippingAddresses' => $Customers_ShippingAddresses,
'span_TrackingNumbers_status' => $TrackingNumbers_status,
'span_TrackingNumbers_email' => $TrackingNumbers_email,
'Submitted_ImportFile' => '@'.$Submitted_ImportFile,
'OVERWRITE' => $OVERWRITE,
'Submit' => 'Upload my files'
);
foreach ($postdata as $key => $value) {
if (strlen($value) < 1) {
unset($postdata[$key]);
};
};
// $postdata_encoded = http_build_query($postdata).'&Submitted_ImportFile=@'.$Submitted_ImportFile;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url.'admin/db_import.asp?UploadID='.$UploadID);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0');
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);
// curl_setopt ($ch,CURLOPT_FAILONERROR, true); // Temporarly added to diagnose issue
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$output = curl_exec ($ch);
// $error = curl_error($ch); // Returns a 400 error
这是包含所有发送的POST数据的数组:
Array
(
[NOSAVE___Form_Submission_Token] => 0D047D55CF3644818EBFEEEF607AD65D
[import_type] => Customers
[Submitted_ImportFile] => @/home/kudchcx/public_html/alpha_test/Customers_test.csv
[OVERWRITE] => Y
[Submit] => Upload my files
)
我检查了网站表单并使用了javascript来确保我拥有所有必要的字段。我对此问题感到茫然。