使用CodeIgniter通过FTP上传文件

时间:2013-12-24 17:46:21

标签: php codeigniter ftp

我正在尝试使用CodeIgniter中的FTP类上传文件。为此,我写了以下内容:

        $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();

但是它告诉我:

  

无法上传指定的文件。请检查你的路径。

我正在使用XAMPP FileZilla连接到我的FTP主机。为此,我创建了没有密码的用户localftp。此用户拥有主机的所有权限。

这是我的本地XAMPP服务器日志记录:

  (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.

在第二行,它说550文件名无效..我认为这是我的问题..请任何人帮我解决这个问题..

2 个答案:

答案 0 :(得分:1)

它就在日志中:

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

您正在尝试命名文件

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

这不是有效的文件名。

尝试删除asset_url()

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

答案 1 :(得分:0)

anon_upload_enable=YES

中对此vsftpd.conf取消评论

位置etc/vsftpd

并使用>重新启动ftp systemctl restart vsftpd

不要使用asset-url()