codeigniter - 文件不会在 CodeIgniter 中上传
问题描述
我想通过 bootstrap modal 上传文件。文件没有上传我已经尝试了其他几种方法我得到了相同的结果。我应该能够上传 pdf 和图像
以下是我的控制器
public function add_file() {
$config['upload_path'] = '/emp/uploads';
$config['allowed_types'] = 'jpg|jpeg|png|pdf';
$config['max_size'] = 2048000;
$config['max_width'] = 1600;
$config['max_height'] = 1600;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file')) {
redirect('employees/display');
} else {
$data['emp_id'] = $this->input->post('emp');
$data ['type'] = $this->input->post('type');
$data ['file_name'] = $this->upload->data('file_name');
$this->employee_model->insert_f($data);
}
}
看法:
<form action="<?php echo base_url('employees/add_file'); ?>" method="post" enctype="multipart/form-data">
<div class="modal fade" id="newmodal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Upload</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label class="col-sm-2 col-form-label">File Type</label>
<input type="text" name="type" class="form-control" >
</div>
<div class="form-group">
<label class="col-sm-2 col-form-label">File</label>
<input type="file" name="file" size="20" class="form-control" >
</div>
<input type="hidden" name="emp" class="form-control" value ="<?php echo$emp->emp_id ?>">
<input type="hidden" name="file_name" class="form-control" >
<div class="modal-footer">
<button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success btn-sm" name="submit"> Save</button>
</div>
</div>
</div>
</div>
</div>
</form>
模型
public function insert_f($data){
$this->db->insert('emp_doc',$data);
$id = $this->db->inser_id();
return $id;
}
请帮我看看哪里出了问题
解决方案
推荐阅读
- postgresql - Postgresql中没有cubedata.h和contrib目录
- javascript - ReferenceError 角度未定义
- c# - 如何将从数据库检索到的 int 转换为字符串
- html - 为什么我的光标在 css 中不起作用?
- docker - 使用通配符和单个命令删除“旧”docker 配置文件
- javascript - 请求不返回完整的响应。错误 JSON.parse
- sql - HiveQL:合并数组列
- wordpress - WooCommerce:从匹配属性中获取产品变体 ID
- opengl - 具有延迟渲染和环境光遮蔽的镜子
- android - React Native + WebView + android 模拟器,WebGL 支持