【发布时间】:2013-11-21 14:50:28
【问题描述】:
我查看了其他答案,但我相信我的问题可能有所不同。我不是 cURL 高手,我希望有人能告诉我应该把我的努力放在哪里。
本地 PHP 脚本传输包含文本值和文件的 $_POST 数组。数据由服务器上的 PHP 脚本接收。等式中没有浏览器。我是从网上找的代码。
在本地开发 HTTP 服务器 (Cherokee) 上完美运行。 在远程实时 HTTP 服务器 (Apache) 上失败。
发送代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
post_array=array("my_file"=>"@".$File,"upload"=>"Upload","var1"=>P1,"var2"=>P2,"var3"=>P3);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
发送脚本将 $_POST 内容显示为:
Array
(
[my_file] => @<path to file>
[upload] => Upload
[var1] => P1
[var2] => P2
[var3] => P3
)
在远程服务器上,$_POST 数组被脚本接收为:
Array
(
[upload] => Upload
)
我正在使用 CURLOPT_VERBOSE,我得到以下屏幕输出:
* About to connect() to <domain name> port 80 (#0)
* Trying 82.71.205.4... * connected
> POST <receiving file> HTTP/1.1
User-Agent: Mozilla/4.0 (compatible;)
Host: <domain name>
Accept: */*
Content-Length: 22091
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------734a2c311f30
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Date: Thu, 21 Nov 2013 14:09:13 GMT
< Server: Apache
< X-Powered-By: PHP/5.3.17
< Content-Length: 199
< Content-Type: text/html
<
* Connection #0 to host <domain name> left intact
Took 0.718261 seconds to send a request to <receiving file>
所以,我知道以下几点:
1/ Script works perfectly on dev server, but on live server...
2/ curl_errno says no errors.
3/ CURLOPT_VERBOSE reports expected array size (22091).
4/ Receiving file receives data, but not $_POST array content.
5/ No entries in server error log.
谁能告诉我应该在哪里调查?
【问题讨论】: