0

我正在尝试使用 php 将文件上传到允许通过表单上传文件的网站。当我尝试运行代码时,我收到“错误请求(无效号码)”错误。然后,当我启用 cURL 在错误时失败时,CURLOPT_FAILONERROR我得到一个“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 来确保我拥有所有必要的字段。我对这个问题不知所措。

4

0 回答 0