我正在尝试将图像存储在FTP服务器上以便在其他页面上使用,但是我在尝试使用此工作时遇到了多个错误。在XAMPP上运行一切。首先,我在html页面上使用输入:
<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 :(得分:1)
更改行
$image = $_POST["image"];
到
$image = $_FILES['image']['tmp_name'];
答案 1 :(得分:0)
当您通过表单上传项目(文件)时,它会填充在$ _FILES超全局中。
通过的上传到当前脚本的关联项目数组 HTTP POST方法。
http://se2.php.net/manual/en/reserved.variables.files.php
确保您还使用enctype='multipart/form-data'
所以PHP的第一行必须改为:
$image = $_FILES['image']['tmp_name'];
$ _FILES是关联的,包含以下数据:
(userfile = image,在您的情况下)
$_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