gpt4 book ai didi

php - 图像未存储在 FTP 中

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:31 24 4
gpt4 key购买 nike

我曾尝试在 php 中使用 ftp 连接将文件上传到服务器,但它无法正常工作,它正在连接但出现错误,如“连接到 XXXXXXXXXXX,用户 XXXXXXXXXXXXX FTP 上传失败!”我已经尝试了以下代码,请帮助更正它,..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Welcome</title>
</head>

<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
<input name="file" type="file" />
<input name="submit" type="submit" value="Upload File" />
</form>
</body>
</html>

上传.php

<?php
$ftp_server = "XXXX";
$ftp_user_name = "XXXXX";
$ftp_user_pass = "XXXXXXXXXX";
$destination_file = "./imagetest/123/";
$source_file = $_FILES['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, FTP_BINARY);

// 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);
?>

最佳答案

您必须在路径后添加文件名。

替换下面的代码试试,

$destination_file = "./imagetest/123/".$_FILES['file']['name'];

关于php - 图像未存储在 FTP 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26277051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com