PHP 警告:ftp_fput():无法打开该文件:目录位于
PHP Warning: ftp_fput(): Can't open that file: Is a directory in
我正在尝试将文件上传到 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 Warning: ftp_fput(): Can't open that file: Is a directory in C:\MAMP\htdocs\mysite\index.php on line 26
我不明白,因为路径是文件。当我在浏览器中粘贴 $local_file
URL 时,声音正在播放。
你的$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;
}
我正在尝试将文件上传到 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 Warning: ftp_fput(): Can't open that file: Is a directory in C:\MAMP\htdocs\mysite\index.php on line 26
我不明白,因为路径是文件。当我在浏览器中粘贴 $local_file
URL 时,声音正在播放。
你的$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;
}