文件上载codeIgniter时出错



下面是我的控制器的代码。。。。

public function do_upload()
{
$config['upload_path']='./upload/';
$config['allowed_types']='gif|jpg|png';
$this->load->library('upload',$config);
$this->upload->do_upload('image_file');
if($this->upload->do_upload('image_file'))
{
$filedata = $this->upload->data();
$filename = $filedata['raw_name'].$filedata['file_ext'];
return $filename;
}
}

在这个调用这个函数之后,你想在哪里进行上传。。。控制器内

if($_FILES)
{
$this->do_upload();
}

但文件未上传。。。。。。。为什么?

希望这将帮助您:

do_upload方法应该是这样的:

public function do_upload() 
{
$config['upload_path'] = './upload/';
$config['allowed_types']='gif|jpg|png';
$this->load->library('upload', $config);
if($this->upload->do_upload('image_file'))
{
$filename = $this->upload->data('file_name');
echo  $filename;die;
}
else
{
print_r($this->upload->display_errors());
die;
}
}

更新

php ini中的set upload_max_filesize大于2MB,

如果是wamp,只需遵循:

click on wamp => php => php settings => upload_max_filesize

我想你错过了这一行。

$config['upload_path']='/上传/';

$config['allowed_types']='gif|jpg|png';


$this->upload->initialize($config(

$this->load->library('pload',$config(;

if($this->upload->do_upload('image_file'(({

$filename = $this->upload->data('file_name');
echo  $filename;die;
}
else
{
print_r($this->upload->display_errors());
die;
}

相关内容

  • 没有找到相关文章

最新更新