问题描述
我知道这个问题可能被问过百万次。我搜索并遵循了上载文件的必要步骤。但是,当我尝试上载文件时,出现了未选择要上载文件的错误。
我的控制器是:
I know this question may have been asked million of times. I searched and followed the required steps for uploading a file.But when i try to upload a file,I get the error of not selecting a file to upload.My controller is:
function save(){
$this->load->library('upload');
$config = array();
$config['upload_path'] = './assets/images/site_data/images/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '100';
$config['file_name'] = time();
$config['overwrite'] = FALSE;
$this->upload->initialize($config);
if($this->upload->do_upload()){
$fInfo = $this->upload->data();
echo '<pre>';
print_r($fInfo);
exit;
}
else
{
echo $this->upload->display_errors();
}
}
我的观点是:
<form method="post" action="<?php echo base_url()?>books/save" enctype="multipart/form-data">
<input type="file" name="cover_photo" id="cover_photo">
<input type="submit" name="save">
</form>
谁能告诉我我的代码有什么问题。如果我做错了,请原谅我。
谢谢。
Can anyone tell me what is wrong with my code.Please forgive me if I have made a mistake.Thanks.
推荐答案
问题是该类希望文件的名称为 userfile
,如文档。
The problem is that the class expects the file to have a name of userfile
as seen in the documentation.
要么更改文件输入的名称,要么将要使用的名称添加到 do_upload
调用中。
Either change the name of the file input or add the name you want to use to the do_upload
call.
后者的示例:
$field_name = "cover_photo";
$this->upload->do_upload($field_name)
这篇关于文件未在codeigniter中上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!