2014-01-15 29 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'];