2014-11-04 163 views
0

我必須在本地系統中使用CURL HTTP POST在Linux命令行中上傳文件。在linux(命令行)中使用cURL的http文件上傳

我已經使用了這些命令,沒有成功:

curl -F "[email protected]/var/www/fbapp/images/registration.png" http://localhost/xmlcreate/curlupload.php 

curl --form "[email protected]/var/www/fbapp/images/registration.png" http://localhost/xmlcreate/curlupload.php 

curl -X POST -d @/var/www/fbapp/images/registration.png http://localhost/xmlcreate/curlupload.php 

curl --data-binary @/var/www/fbapp/images/registration.png http://localhost/xmlcreate/curlupload.php 

我用所有這些命令,但這些都不奏效。

這是我PHP文件,其中我試圖讓上傳的文件(使用curl),並將其保存在其他目錄:

<?php 
$uploadpath = "images/"; 
$filedata = $_FILES['image']['tmp_name']; 
$filename = $_POST['filename']; 
if ($filedata != '' && $filename != '') 
    copy($filedata,$uploadpath.$filename); 
?> 

可有人請幫我這。我被困在這裏,無法前進。

一旦它開始在本地工作,我必須使用遠程服務器的URL,而不是本地主機。

回答

1

嘗試

curl -i -F filename=image.jpg -F [email protected]/path/to/image.jpg http://localhost/xmlcreate/curlupload.php 
+0

我得到這個作爲輸出:HTTP/1.1 100繼續 HTTP/1.1 200 OK 日期:星期二,2014年11月4日13時01分49秒GMT 服務器:Apache/2.2.22(Ubuntu的) X-供電-By:PHP/5.3.10-1ubuntu3.13 Vary:Accept-Encoding Content-Length:0 Content-Type:text/html – 2014-11-04 13:03:08

+0

文件上傳了嗎?由於您的腳本不輸出任何內容,因此很難說它是否有效! – motanelu 2014-11-04 13:05:06

+0

我嘗試使用.png文件 – 2014-11-04 13:07:00

0

嘗試使用

move_uploaded_file() 

我覺得你捲曲的至少一個命令的工作。檢查簡單地把這樣的東西:

file_put_contents('log.txt',print_r($_FILES,true)); 

在你的代碼,並檢查你從捲曲實時得到什麼。