0

フォームからファイルをアップロードできる Web サイトに、php を使用してファイルをアップロードしようとしています。コードを実行しようとすると、「Bad Request (Invalid Number)」エラーが発生します。次に、cURL がエラーで失敗するCURLOPT_FAILONERRORようにすると、「400 エラー」が発生します。すべてを正しく入力したと思います。同じ Web サイトから同様の形式でファイルをダウンロードしました。

$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