PHP Warning: ftp_fput(): Can#39;t open that file: Is a directory in(PHP 警告:ftp_fput():无法打开该文件:是一个目录)
问题描述
我正在尝试将文件上传到 FTP.
I'm trying to upload a file to 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:MAMPhtdocsmysiteindex.php 中的目录
PHP Warning: ftp_fput(): Can't open that file: Is a directory in C:MAMPhtdocsmysiteindex.php on line 26
我不明白,因为路径是文件.当我在浏览器中粘贴 $local_file URL 时,声音正在播放.
I don't understand because the path is the file. When I paste $local_file URL in my browser the sound is playing.
推荐答案
你的 $local_file 是可以的,但是你的 $remote_file 是一个目录(你使用 '/' . $date for ftp_chdir),它需要是一个文件的路径(将被创建)
Your $local_file is OK, but your $remote_file is a directory (you use '/' . $date for ftp_chdir), and it need to be a path to a file (that will be created)
您可以使用 basename 复制与本地文件相同的文件名:
You can copy the same filename than the local file with 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;
}
这篇关于PHP 警告:ftp_fput():无法打开该文件:是一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 警告:ftp_fput():无法打开该文件:是一个目录
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
