PHP Curl上传,按数组中设置的顺序发布值 [英] PHP Curl upload, post values in order as set in array

查看:81
本文介绍了PHP Curl上传,按数组中设置的顺序发布值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将带有cURL的文件上传到远程服务器时遇到问题. 仅当POST变量按顺序排列时,远程服务器才接受文件. 就我而言:sid,cmd,uploadfile 我按此顺序用一个简单的HTML上传表单对其进行了测试,一切正常.但是,如果我替换输入字段的顺序,例如:cmd,sid,uploadfile 它拒绝了我的上传.

I have a problem with uploading files with cURL to remote server. The remote server only accepts the file only if the POST variables coming in order. In my case: sid, cmd, uploadfile I tested it with a simple HTML upload form in this order, everything ok. But if I replace the order of input fields, like: cmd, sid, uploadfile it rejects my upload.

这是我的cURL代码,它没有按照我在数组中设置的顺序发送变量. 如何强制cURL以与设置变量相同的顺序进行POST.

So here is my cURL code, it doesn't send the variables in the order I set in array. How do I force cURL to POST in the same order as I set the variables.

$file = "/var/www/html/dl/big.mp4";

$target_url = 'http://upload.site/uploadpage';
$file_name_with_full_path = realpath($file);
$post = array('sid' => 'H1nbWKcdYP7eS7DzJk0Z6BjGaC842vPO', 'cmd' => 'uploadVideoFiles', 'uploadfile'=>'@'.$file_name_with_full_path);

$ch = curl_init();
$browser = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0';
curl_setopt($ch, CURLOPT_USERAGENT, $browser);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: en-US,en;q=0.5',
'Cache-Control: max-age=0',
'Connection: keep-alive',
'Host: upload.sitehost',
    )                                                                 
);    
$result=curl_exec($ch);
curl_close ($ch);
echo $result;

推荐答案

我解决了问题,这是我的错,cmd不是

I solved the problem, it was my fault, the cmd was not

'cmd' => 'uploadVideoFiles'

是:

'cmd' => 'uploadVideoFile'

这篇关于PHP Curl上传,按数组中设置的顺序发布值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆