我想直到今天我用這個代碼上傳單個圖像如何從單一的輸入笨上傳多張圖片的Fileds
對我的畫廊 上傳多張圖片我控制器
public function addPhoto($album_id)
{
if ($this->input->post('submit')) {
$this->form_validation->set_rules('caption', 'Caption', 'required');
$this->form_validation->set_rules('userfile', 'Image', 'callback__checkImage');
if ($this->form_validation->run()) {
$config['upload_path'] = $this->config->item('upload_path');
$config['allowed_types'] = $this->config->item('allowed_types');
$config['max_size'] = $this->config->item('max_size');
$config['max_width'] = $this->config->item('max_width');
$config['max_height'] = $this->config->item('max_height');
$config['encrypt_name'] = $this->config->item('encrypt_name');
$this->load->library('upload', $config);
if ($this->upload->do_upload()) {
$image = $this->upload->data();
$this->album_model->addPhoto($image['file_name'], $album_id);
$this->session->set_flashdata('msg', 'Photo added successfully.');
redirect('album/photos/'.$album_id);
} else {
$this->session->set_flashdata('msg', $this->upload->display_errors());
redirect('album/addPhoto/'.$album_id);
}
}
}
$data['title'] = 'Add Photo';
$data['content'] = $this->load->view('album/add_photo', '', true);
$this->load->view('template', $data);
}
我車型
function addPhoto($image, $album_id)
{
$this->db->set('name', $image);
$this->db->set('caption', $this->input->post('caption'));
$this->db->set('album_id', $album_id);
$this->db->insert('photos');
}
和我的看法是
<form action="" method="post" enctype="multipart/form-data">
<h1>Add Photo</h1>
<?php echo $this->session->flashdata('msg'); ?>
<div>
<label>Image</label>
<input type="file" name="userfile">
<?php echo form_error('userfile'); ?>
</div>
<br>
<div>
<label>Caption</label>
<input type="text" name="caption" value="<?php echo set_value('caption'); ?>" placeholder="Caption">
<?php echo form_error('caption'); ?>
</div>
<br>
<div>
<label></label>
<button type="submit" name="submit" value="submit">Upload</button>
</div>
</form>
這就是我用來上傳單張圖片現在我想上傳多個,我只有一個圖片字段上的數據庫,我需要做更多的圖片字段上傳多張圖片?
它的jQuery插件它多張圖片發到我databsae ???? –
是的,但你必須編碼,它會發送所有上傳的文件的詳細信息到你的行動。 –