我想通过 FTP 上传表单中的文件.
I want to upload a file via FTP upload in a form.
<html>
<body>
<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
这里是 PHP 文件:
Here is the PHP file:
<?php
$ftp_server = "xxx";
$ftp_username = "xxx";
$ftp_password = "xxx";
// setup of connection
$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");
// login
if (@ftp_login($conn_id, $ftp_username, $ftp_password))
{
echo "conectd as $ftp_username@$ftp_server
";
}
else
{
echo "could not connect as $ftp_username
";
}
$file = $_FILES["file"]["name"];
$remote_file_path = "/home/www/lifestyle69/import/".$file;
ftp_put($conn_id, $remote_file_path, $file, FTP_ASCII);
ftp_close($conn_id);
echo "
connection closed";
?>
FTP连接成功,但文件不存在.
The FTP connection connects successfully but the file is nowhere.
谁能帮帮我?
谢谢!
因为你有 <input name="uploadedfile" type="file"/>
:
$file = $_FILES["file"]["name"]; // wrong
$file = $_FILES["uploadedfile"]["name"]; // right
因为你需要PHP存储的临时副本的文件名,它存在于服务器上:
Because you need the filename of the temporary copy stored by PHP, which exists on the server:
ftp_put($conn_id, $remote_file_path, $file, FTP_ASCII); // wrong
ftp_put($conn_id, $remote_file_path, $_FILES["uploadedfile"]["tmp_name"],
FTP_ASCII); // right
有关详细信息,请参阅 PHP 文档大约 $_FILES.
Refer to the PHP documentation for more information about $_FILES.
这篇关于通过 PHP 表单进行 FTP 上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!