PHP警告:ftp_fput():无法打开该文件:是目录位于

问题描述 投票:0回答:1

我正在尝试将文件上传到FTP。

这是我的代码:

$connect = ftp_connect('ftp.my-server.fr');
$login = ftp_login($connect, 'username', 'pass');

$remote_file = '/' . $date;
$local_file = fopen('C:/MAMP/htdocs/mysite/myfolder/' . $hour .'.mp3', 'r');

ftp_chdir($connect, '/'.$date);

if (ftp_fput($connect, $remote_file, $local_file, FTP_ASCII)) {
    echo "The file $local_file has been loaded";
} else {
    echo "Error while uploading file " . $local_file;
}

我遇到错误:

PHP警告:ftp_fput():无法打开该文件:是第26行上C:\ MAMP \ htdocs \ mysite \ index.php中的目录

我不明白,因为路径是文件。当我在浏览器中粘贴$local_file URL时,声音正在播放。

php ftp
1个回答
2
投票

您的$local_file正常,但是您的$remote_file是目录(您将'/' . $date用作ftp_chdir),并且它必须是文件路径(将要创建)]

您可以使用basename复制与本地文件相同的文件名:

$remote_dir = '/' . $date;
$local_file = fopen('C:/MAMP/htdocs/mysite/myfolder/' . $hour .'.mp3', 'r');

ftp_chdir($connect, $remote_dir);
$remote_file = $remote_dir . '/' . basename($local_file) ;

if (ftp_fput($connect, $remote_file, $local_file, FTP_ASCII)) {
    echo "The file $local_file has been loaded";
} else {
     echo "Error while uploading file " . $local_file;
}
© www.soinside.com 2019 - 2024. All rights reserved.