我要制作图片库。当我选择要上传的图像时,其成功保存到数据库中。但不会显示在页面上。并仅显示“文件成功上传”消息。不知道我在哪里弄错了。 没有显示错误。由于没有错误,如何解决此问题。
查看:
<?php if(!empty($gallery)): foreach($gallery as $file): ?>
<img src="<?php echo base_url("assets/users".$file['path']); ?>" alt="" >
<!--<p>Uploaded On <?php /*echo date("j M Y",strtotime($file['created'])); */?></p>-->
<?php endforeach; else: ?>
<p>No File uploaded.....</p>
<?php endif; ?>
<div class="form-group col-sm-3">
<label>Choose Files</label>
<input type="file" class="form-control" name="upload_Files[]" multiple/>
</div>
<div class="form-group col-sm-6">
<input type="submit" class="btn btn-default" name="submitForm" id="submitForm"/>
</div>
控制器:
function upload() {
if($this->generic->IsUserLoggedIn()){
$userId = $this->session->userdata('ID');
$data = array();
if($this->input->post('submitForm') && !empty($_FILES['upload_Files']['name'])){
$filesCount = count($_FILES['upload_Files']['name']);
for($i = 0; $i < $filesCount; $i++){
$_FILES['upload_File']['name'] = $_FILES['upload_Files']['name'][$i];
$_FILES['upload_File']['type'] = $_FILES['upload_Files']['type'][$i];
$_FILES['upload_File']['tmp_name'] = $_FILES['upload_Files']['tmp_name'][$i];
$_FILES['upload_File']['error'] = $_FILES['upload_Files']['error'][$i];
$_FILES['upload_File']['size'] = $_FILES['upload_Files']['size'][$i];
$uploadPath = "assets/users/".$this->session->userdata('ID');
$config['upload_path'] = $uploadPath;
$config['allowed_types'] = 'gif|jpeg|jpg|png';
$this->load->library('upload', $config);
/*$date = str_replace( ':', '', $date);*/
$this->upload->initialize($config);
if (!is_dir("assets/users/".$this->session->userdata('ID'))) {
mkdir("assets/users/".$this->session->userdata('ID'), 0777, TRUE);
}
if($this->upload->do_upload('upload_File')){
$fileData = $this->upload->data();
$uploadData[$i]['user_id'] = $userId; // For user_id value
$uploadData[$i]['path'] = $fileData['file_name'];
$uploadData[$i]['media_type'] = pathinfo($uploadData[$i]['path'],PATHINFO_EXTENSION);
}
}
if(!empty($uploadData)){
//Insert file information into the database
$insert = $this->User->insert($uploadData);
$statusMsg = $insert?'Files uploaded successfully.':'Some problem occurred, please try again.';
$this->session->set_flashdata('statusMsg',$statusMsg);
}
}
$data['gallery'] = $this->User->getRows();
$this->load->view('imagegallery', $data);
}
}
型号:
public function getRows($id = ''){
$this->db->select('user_id,path');
$this->db->from('mh_user_media');
if($id){
$this->db->where('user_id',$id);
$query = $this->db->get();
$result = $query->row_array();
}else{
$this->db->order_by('path','desc');
$query = $this->db->get();
$result = $query->result_array();
}
return !empty($result)?$result:false;
}
public function insert($data = array()){
$insert = $this->db->insert_batch('mh_user_media',$data);
return $insert?true:false;
}