无法找到源文件。请检查你的路径

时间:2013-03-16 08:58:45

标签: php codeigniter ftp

我尝试使用codeigniter ftp class上传文件。

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

    $config['hostname'] = 'www.domain.com';

    $config['username'] = 'xxxxxxxxx';

    $config['password'] = 'xxxxxxxx';

    $config['port']     = 21;

    $config['passive']  = FALSE;

    $config['debug']    = TRUE;

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

    $this->ftp->upload('C:\Users\SYSTEM2\Desktop\checking\ash.jpg\' ,  base_url().'uploads/myfolder/ash.jpg/');

    $this->ftp->close();

但显示此错误

“无法找到源文件。请检查您的路径。” 请帮助我解决这个问题...

3 个答案:

答案 0 :(得分:1)

尝试$this->ftp->upload('C:/Users/SYSTEM2/Desktop/checking/ash.jpg' , '/www/uploads/myfolder/');这对我来说非常好运

答案 1 :(得分:0)

而不是这个

$this->ftp->upload('C:\Users\SYSTEM2\Desktop\checking\ash.jpg\' ,  base_url().'uploads/myfolder/ash.jpg/');

使用

 $this->ftp->upload('C:\Users\SYSTEM2\Desktop\checking\ash.jpg','/www/uploads/myfolder/ash.jpg');

但你应该知道你的ftp服务器的根路径,有时它是“/ www / yourdomen /".

答案 2 :(得分:0)

Codeigniter ftp类检查文件是否先存在,然后执行上传,你可以看一下codeigniter文件夹中的代码 system \ libraries \ FTP.php 第238行

if ( ! file_exists($locpath))
{
 $this->_error('ftp_no_source_file');
 return FALSE;
}

根据php.net站点,如果您将file_exists与Web服务器外部的本地文件一起使用,则本地文件路径应采用// computername / share / filename格式。

表示您必须将文件放在具有公共权限的共享文件夹中。

如果您设置正确并确保权限允许来自网络的用户访问该文件,那么它可能会起作用。

我建议您使用表单而不是手动编写文件路径,然后编写代码如下:

$file=$_FILES["userfile"]["name"];
$this->ftp->upload($file ,  './upload','ascii', 0775);
相关问题