Liv*_*eEn 7 php codeigniter file-upload
我试图上传图像,但它总是给我"你没有选择要上传的文件."
我的控制器
function add()
{
$thedate=date('Y/n/j h:i:s');
$replace = array(":"," ","/");
$newname=str_ireplace($replace, "-", $thedate);
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name']=$newname;
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//$this->upload->initialize($config);
$this->load->library('form_validation');
$this->form_validation->set_rules('title','title','trim|required');
$this->form_validation->set_rules('description','Description','trim|required');
$image1=$this->input->post('image');
if ($this->form_validation->run()==FALSE){
$this->addview();
return false;
}
if (!$this->upload->do_upload($image1)) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_error', $error);
}
else {
$mage=$this->upload->do_upload($image1);
$data =array(
'title'=>$this->input->post('title'),
'descrip'=>$this->input->post('description'),
'image' => $mage['file_name']
);
$this->load->model('member_functions');
$q=$this->member_functions->insert($data);
}}
Run Code Online (Sandbox Code Playgroud)
设置了所有文件要求和文件权限,但我仍然得到了那个错误.有人可以告诉我,我做错了什么
cen*_*zen 22
$this->upload->do_upload()函数的参数应该是表单字段的名称.(如果你不使用参数调用它将userfile被使用).在你的情况下,它似乎应该是'形象'.代替:
$image1=$this->input->post('image');
Run Code Online (Sandbox Code Playgroud)
它应该是:
$image1='image';
Run Code Online (Sandbox Code Playgroud)
小智 6
表格标签应包含enctype="multipart/form-data".
即
<form action='' method=''enctype="multipart/form-data>
<input type='file' name='field_name'/>
并且在控制器上传代码中应该$this->upload->do_upload("field_name")
和jsut一样通过打印来检查文件是否到达服务器端
print_r($_FILES);
Run Code Online (Sandbox Code Playgroud)
如果你得到空数组,那么请确保客户端代码是正确的.
| 归档时间: |
|
| 查看次数: |
34557 次 |
| 最近记录: |