San*_*Rao 2 linux post curl http
我一直试图在linux命令行中使用此命令将文件上传到服务器:
curl -v --data 'file=@/var/www/fbapp/images/registration.png' http://myserver/xmltest/curlupload.php
Run Code Online (Sandbox Code Playgroud)
但它没有将文件上传到服务器,即使它正在发送响应.
虽然如果我使用此命令,它将上传文件并发回响应:
curl -v -F 'filename=registration.png' -F 'file=@/var/www/fbapp/images/registration.png' http://myserver/xmltest/curlupload.php
Run Code Online (Sandbox Code Playgroud)
但我想要curl --data格式本身的命令.
这是我在服务器中的PHP代码:
<?php
$uploadpath = "images/";
$filedata = $_FILES['file']['tmp_name'];
echo "filedata= ".$filedata;
if ($filedata != '')
copy($filedata,$uploadpath."1.png");
echo "success";
?>
Run Code Online (Sandbox Code Playgroud)
这是我得到的标题响应:
> POST /xmltest/curlupload.php HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: myserver
> Accept: */*
> Content-Length: 44
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 44out of 44 bytes
< HTTP/1.1 200 OK
< Date: Thu, 06 Nov 2014 07:01:56 GMT
< Server: Apache
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html
<
* Connection #0 to host myserver left intact
* Closing connection #0
filedata= success
Run Code Online (Sandbox Code Playgroud)
如何使用curl --data上传文件?
你通常不能简单地选择-F或-d( - data).将收到您的帖子的Web服务器需要其中一种格式.如果您尝试提交的表单使用"multipart/form-data"类型,那么您必须使用-F类型.如果没有,您应该使用-d然后导致类型为'application/x-www-form-urlencoded'的发布.
带有-F的multipart/formposts使用帖子的特殊格式,其中Mime-headers分隔不同的部分,每个部分都有自己的标题集.
-d只是发送给服务器解释/解码的原始数据.
卷曲常见问题解答中提到过.
(但是既然你在这种情况下编写PHP代码,你只需要决定你想接受哪种POST方法,然后让你的curl命令行使用它.)
| 归档时间: |
|
| 查看次数: |
28393 次 |
| 最近记录: |