【问题标题】:FTP_PUT in PHP and the remote File SystemPHP 中的 FTP_PUT 和远程文件系统
【发布时间】:2020-11-17 02:59:29
【问题描述】:
ftp_stream
The link identifier of the FTP connection.

remote_file
The remote file path.

local_file
The local file path.

mode
The transfer mode. Must be either FTP_ASCII or FTP_BINARY.

startpos
The position in the remote file to start uploading to.

https://www.php.net/manual/en/function.ftp-put.php

我仍然难以理解该链接中的许多内容。

问题:

$upload = ftp_put($newconn->conn,$destination,$source, FTP_BINARY);

实际的目的地和来源是什么?

$destination 是远程文件,$source 只是文件?

如果我们想把上传的内容放到某个文件夹中。我们必须开始pos吗 位置作为该文件夹位置?

更新:

我正在使用这个:

$filename = "message.txt";
$source = getcwd()."/".$filename;
echo "The source file path is: ". $source;
echo "<br />";
$destination=getcwd()."/"."ftpsend/";
echo "The destination file path is: ". $destination;
echo "<br />";
$upload = ftp_put($newconn->conn,$destination,$source, FTP_BINARY);

我收到此错误:

在 Filezilla 中显示此路径 →

【问题讨论】:

    标签: php file upload


    【解决方案1】:

    根据文档中的this comment

    你不能放置目标文件的路径

    所以你必须使用ftp_chdir() 来指定目标目录。

    您不应该将目标目录连接到 getcwd(),因为这是您本地计算机上的路径名,而不是远程服务器上的路径名。

    $filename = "message.txt";
    $source = getcwd()."/".$filename;
    echo "The source file path is: ". $source;
    echo "<br />";
    $destination="/app.trafficopedia.com/ftp";
    echo "The destination file path is: ". $destination;
    echo "<br />";
    ftp_chdir($newconn->conn,$destination);
    $upload = ftp_put($newconn->conn,$filename,$source, FTP_BINARY);
    

    【讨论】:

    • 嗨,请看我更新的帖子。感谢您的认可。
    • 还是有错误→app.trafficopedia.com/ftp
    • Filezilla 显示此路径。我们可以通过手动文件路径测试它吗→ /app.trafficopedia.com/ftp
    • app.trafficopedia.com实际上是目录名,还是只是远程服务器的名字?
    • 这是代码ibb.co/M6Qqx7B的当前状态,但它仍然会产生错误。我尝试使用 filezilla 中显示的路径。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多