dse55384 2013-12-24 17:46
浏览 57
已采纳

使用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 2013-12-24 18:33
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来