PHP Warning: ftp_fput(): Can't open that file: Is a directory in

后端 未结 1 1706
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 02:14

I\'m trying to upload a file to FTP.

Here is my code:

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


        
1条回答
  •  不知归路
    2021-01-17 02:54

    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)

    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;
    }
    

    0 讨论(0)
提交回复
热议问题