2012-09-02 22 views
0

我有幾個關於cURL的基本問題,我無法在cURL文檔中找到答案(可能是因爲它們對其他人都是顯而易見的......)。我有一個需要將該文件發送到遠程服務器的窗體中的文件類型輸入。 cURL代碼是使用表單在頁面上進行的,還是表單發送給您的頁面上的cURL,然後將其發送到遠程服務器?PHP cURL設置發送到遠程主機

這裏是HTML表單:

<form action="send.php" method="post" enctype="multipart/form-data"> 
    <label for="file">Filename:</label> 
    <input type="file" name="file" id="file" /> 
    <br /> 
    <input type="submit" name="submit" value="Submit" /> 
</form> 

捲曲的PHP我到目前爲止,我甚至不知道這是否是正確的我想要做的,或者,如果這樣下去的同頁面或send.php文件的形式進入:

$ch = curl_init("http://remoteServer/upload_file.php"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CUROPT_POSTFIELDS, array('fileupload' => '@'.$_FILES['theFile']  ['tmp_name'])); 
echo curl_exec($ch);` 

和遠程服務器我有這個文件就接受它:

$folder = "files/"; 
$path = $folder . basename($_FILES['file']['name']); 
if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) { 
    echo "The file ". basename($_FILES['file']['name']). " has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
} 

這甚至是遠程關閉?

+0

您不需要使用捲曲從一個瀏覽器接收文件上傳。 –

回答

0

你不需要捲曲從瀏覽器上傳文件,可以直接提交表單到遠程服務器上傳 - 只要確保表單提交到任何文件具有的代碼第三塊

+0

我試過了,每次都收到錯誤信息。我在這裏發佈了一個關於它的問題,並且大家都說使用cURL或ftp。如果我要刪除cURL,文件如何實際到達遠程服務器? – Milksnake12

0

試試這個

$curlPost = array('fileupload' => '@'.$_FILES['theFile'] ['tmp_name']); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://remoteServer/upload_file.php'); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); 
$data = curl_exec(); 
curl_close($ch); 

另一個例子

如何圖像文件上傳到遠程服務器與PHPç URL

http://www.maheshchari.com/upload-image-file-to-remote-server-with-php-curl/

+0

我正在查看鏈接,但我仍然不確定cURL代碼的位置。看看這個鏈接的例子,我得到了它在遠程服務器上的印象,這是否正確? – Milksnake12