我一直在試圖把文件上傳到在Linux命令行使用此命令的服務器:捲曲HTTP POST文件上傳
curl -v --data '[email protected]/var/www/fbapp/images/registration.png' http://myserver/xmltest/curlupload.php
但不上傳文件到服務器,即使它正在發回響應。
雖然如果我用這個命令將上傳文件併發送回響應:
curl -v -F 'filename=registration.png' -F '[email protected]/var/www/fbapp/images/registration.png' http://myserver/xmltest/curlupload.php
但我想在捲曲--data格式本身的命令。
這是在我的服務器PHP代碼:
<?php
$uploadpath = "images/";
$filedata = $_FILES['file']['tmp_name'];
echo "filedata= ".$filedata;
if ($filedata != '')
copy($filedata,$uploadpath."1.png");
echo "success";
?>
這是標題的響應,我找回:
> 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
如何使用捲曲--data上傳文件?
可能重複請求通過CURL文件指定的數據](http://stackoverflow.com/questions/6408904/how-to-send-post-request-with-data-specified-in-file-via-curl) – Jens 2014-11-06 07:20:20