【发布时间】:2016-09-21 14:55:54
【问题描述】:
我在通过 PHP 从我的网站上传到 FTP 时遇到问题。
连接正常,但上传图片时出现问题。
HTML
<form action="../scripts/php/saveupload.php" method="post">
<input name="file" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form>
PHP
$ftp_server = "XXXXXX";
$ftp_user_name = "XXXXX";
$ftp_user_pass = "XXXXX";
$destination_file = "/public_html/img/news/";
$source_file = $_FILE['file']['tmp_name'];
// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
我收到的信息是:
"连接到ftp.theucl.co.uk,对于用户theucl.co.ukFTP上传有 失败!”
This is now the error I am getting after following Niths advice on the error...
似乎错误在以下..
$source_file = $_FILES['file']['tmp_name'];
和
$upload = ftp_put($conn_id, $destination_file.$_FILES['file']['tmp_name'], $source_file,FTP_ASCII);
显然这之间有一个共同的表现
【问题讨论】:
-
那些不是你的真实凭证……是吗?
-
检查文件夹权限。我猜当前权限设置为755。设置为777
-
我建议不要将权限设置为 777。这是一个安全风险。虽然检查文件夹权限是否正确是有效的。
-
您好,请阅读我的回答,如果您需要任何其他信息,请尽快联系我。
-
@JonStirling 不,他们不是。其次,我的主机在控制面板上似乎没有用于文件夹检查的选项。