【问题标题】:Moving an uploaded file onto a remote server将上传的文件移动到远程服务器
【发布时间】:2012-03-26 04:39:51
【问题描述】:

我正在尝试将上传的文件移动到远程服务器上,这不起作用;

move_uploaded_file($tmp_name, "uploads/$code1/$code.$fileex");

$ftp_server = "IP";
$ftp_user_name = "username";
$ftp_user_pass = "password";
$file = $tmp_name;
$remote_file = "/public_html/test/uploads/";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);

我得到了这个错误;

警告:ftp_put() [function.ftp-put]:无法打开该文件:是第 52 行 /home/file/public_html/uploaded.php 中的目录

【问题讨论】:

    标签: php ftp


    【解决方案1】:

    您的$remote_file 变量指向一个目录,而它应该指向一个文件。尝试将 $remote_file 更改为 $remote_file = "/public_html/test/uploads/".$file;

    【讨论】:

    • 我正在尝试将本地文件移动到远程服务器。
    • 是的,我明白这一点。您需要指定远程服务器上的路径,包括文件名,但是在您的代码中您没有这样做。如果您查看 ftp_put (us.php.net/manual/en/function.ftp-put.php) 的文档,您会看到第二个参数是远程文件,而不是远程文件夹。
    【解决方案2】:

    您可能应该将上传文件的部分包装在 if 语句中,以检查您是否实际正确连接到 FTP

    另外,上传文件时,您需要文件 1 和文件 2。现在您已经提供了文件 2 和目录。

    http://php.net/manual/en/function.ftp-put.php

    【讨论】:

      【解决方案3】:

      您要移动到的文件是目录"/public_html/test/uploads/",您需要将文件名和扩展名附加到目录中。

      【讨论】:

        【解决方案4】:

        在 /etc/vsftpd.conf 文件末尾添加以下行

        添加 pasv_promiscuous=YES

        【讨论】:

        • 它在 ubuntu 14 中使用 64 位 aws 服务器为我工作
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-28
        • 2015-12-15
        • 1970-01-01
        • 2017-05-23
        • 1970-01-01
        相关资源
        最近更新 更多