dse55384
dse55384
2013-12-24 17:46

使用CodeIgniter通过FTP上传文件

已采纳

I am trying to upload a file using the FTP class in CodeIgniter. For that I have written the following:

        $this->load->library('ftp');

        $config['hostname'] = '127.0.0.1';
        $config['username'] = 'localftp';
        $config['password'] = '';
        $config['debug'] = TRUE;

        $this->ftp->connect($config);

        $this->ftp->upload($_FILES['book_file']['tmp_name'], asset_url()."books/" . $_FILES['book_file']['name'], "ascii", 0775);

        $this->ftp->close();

but it is showing me :

Unable to upload the specified file. Please check your path.

I am using XAMPP FileZilla to connect to my FTP host. For that I have created the user localftp with no password. And this user has all the permissions on the host.

and this is my local XAMPP server logging:

  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> Connected, sending welcome message...
  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> 220-FileZilla Server version 0.9.41 beta
  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> 220 Please visit http://sourceforge.net/projects/filezilla/
  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> USER localftp
  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> 331 Password required for localftp
  (000016)24-Dec-13 23:27:05 PM - (not logged in) (127.0.0.1)> PASS
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> 230 Logged on
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> PASV
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> 227 Entering Passive Mode    (127,0,0,1,205,219)
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> TYPE A
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> 200 Type set to A
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> STOR   http://localhost/International/public/books/ftpupload.pdf
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> 550 Filename invalid
  (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> disconnected.

on the second last line it is saying 550 filename invalid.. I think this is my problem.. Please can any one help me out to solve this issue..

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • duang8642 duang8642 8年前

    It's right there in the log:

    (000016)24-Dec-13 23:27:05 PM - localftp (127.0.0.1)> STOR http://localhost/International/public/books/ftpupload.pdf
    

    You are trying to name the file

    http://localhost/International/public/books/ftpupload.pdf
    

    which is not a valid filename.

    Try removing asset_url():

    $this->ftp->upload($_FILES['book_file']['tmp_name'], "books/" . $_FILES['book_file']['name'], "ascii", 0775);
    
    点赞 评论 复制链接分享
  • dongtui4038 dongtui4038 4年前

    un-comment this anon_upload_enable=YES in vsftpd.conf

    location etc/vsftpd

    and restart ftp using > systemctl restart vsftpd

    don't use asset-url()

    点赞 评论 复制链接分享

相关推荐