douba1067 2013-07-18 21:20
浏览 127

使用POST使用cURL上传文件会返回错误“错误请求(无效数字)”

I am attempting to upload a file using php to a website that allows files to be uploaded through a form. When I try to run the code, I get a "Bad Request (Invalid Number)" error. Then when I enabled the cURL to fail on error with CURLOPT_FAILONERROR I get a "400 error". I think I've typed in everything correctly, I've downloaded files from the same website on a similar form they have.

$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

Here is the array containing all the POST data that is sent:

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
)

I've checked the website forms and used javascript to make sure I have all the necessary fields. I am at a loss for this issue.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 软件自定义无线电该怎样使用
    • ¥15 Jenkins+k8s部署slave节点offline
    • ¥15 微信小游戏反编译后,出现找不到分包的情况
    • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
    • ¥15 WPF使用Canvas绘制矢量图问题
    • ¥15 用三极管设计一个单管共射放大电路
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
    • ¥15 怎么把多于硬盘空间放到根目录下