2014-01-15 73 views
0

我試圖將圖像存儲在FTP服務器上以用於其他頁面,但我得到了多個錯誤,試圖獲得這項工作。在XAMPP上運行一切。首先,我用輸入HTML頁上:從HTML輸入將圖像上傳到ftp

<input type="file" name="image" required> 

然後我把它過度,並嘗試將其上傳:

$image = $_POST["image"]; 
$ftpCon = ftp_connect("127.0.0.1", "21") or die("Could not connect to FTP"); 
ftp_fput($ftpCon, "image.png", $image, FTP_BINARY); 
ftp_close($ftpCon); 

有了這個代碼,我得到這個錯誤:「ftp_fput()預計參數3要資源,串給」

回答

0

當您通過表單上載項目(文件)時,它會填充到$ _FILES超全局中。

An associative array of items uploaded to the current script via the HTTP POST method.

http://se2.php.net/manual/en/reserved.variables.files.php

確保您還設置形式與enctype='multipart/form-data'

所以PHP的第一行已更改爲:

$image = $_FILES['image']['tmp_name']; 

的$ _FILES是associtaive幷包含以下數據:

(userfile的=像,你的情況)

$_FILES['userfile']['name'] 
The original name of the file on the client machine. 
$_FILES['userfile']['type'] 
The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted. 
$_FILES['userfile']['size'] 
The size, in bytes, of the uploaded file. 
$_FILES['userfile']['tmp_name'] 
The temporary filename of the file in which the uploaded file was stored on the server. 
$_FILES['userfile']['error'] 
The error code associated with this file upload. This element was added in PHP 4.2.0 
+0

感謝偉大的解釋,但實際上現在它給我「......空給」,而不是字符串,即使我複製的加密類型的形式和替換$ _POST,$ image = $ _FILES ['image'] ['tmp_name'];任何關於現在發生的事情的想法? – user3150430

1

更改線路

$image = $_POST["image"]; 

$image = $_FILES['image']['tmp_name'];