Php 上传多张图片';t存储到数据库和路径文件夹
我正在上传多个图像并存储到一个字段。但我的代码有一个问题,图像不能存储到数据库和路径文件夹。也许你能帮助我 这是我的控制器Php 上传多张图片';t存储到数据库和路径文件夹,php,codeigniter,Php,Codeigniter,我正在上传多个图像并存储到一个字段。但我的代码有一个问题,图像不能存储到数据库和路径文件夹。也许你能帮助我 这是我的控制器 public function post() { if(empty($_FILES['file']['name'])) { $data = array( 'id_merk' => $this->input->post('id_merk'),
public function post() {
if(empty($_FILES['file']['name'])) {
$data = array( 'id_merk' => $this->input->post('id_merk'),
'createdAt' => $this->input->post('createdAt')
);
// var_dump($data);
$this->m_barang->post( $data );
$this->session->set_flashdata('success', 'success');
redirect('admin/merk');
} else {
$count = count($_FILES['file']['size']);
foreach($_FILES as $value){
for($s=0; $s<=$count-1; $s++) {
$_FILES['file']['name'] = $value['name'][$s];
$_FILES['file']['type'] = $value['type'][$s];
$_FILES['file']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['file']['error'] = $value['error'][$s];
$_FILES['file']['size'] = $value['size'][$s];
// $config['file_name'] = 'pict_'.date('Y_m_d_H_i_s').'.jpg';
$config['upload_path'] = './upload/be/barang';
$config['allowed_types'] = 'gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG';
$config['max_size'] = '8000';
$config['max_width'] = '1366';
$config['max_height'] = '1024';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
}
$names = implode(', ', $name_array);
$data = array( 'id_merk' => $this->input->post('id_merk'),
'photo_barang' => $names
);
$this->m_barang->post( $data );
$this->session->set_flashdata('success', 'gambar ada');
redirect('admin/merk');
}
}
公共职能职位(){
if(空($_文件['file']['name'])){
$data=array('id\u merk'=>$this->input->post('id\u merk'),
'createdAt'=>$this->input->post('createdAt')
);
//var_dump($数据);
$this->m_barang->post($data);
$this->session->set_flashdata('success','success');
重定向('admin/merk');
}否则{
$count=计数($_文件['file']['size']);
foreach($\u文件为$value){
对于($s=0;$sload->library('upload',$config));
$this->upload->do_upload();
$data=$this->upload->data();
$name_数组[]=$data['file_name'];
}
}
$names=内爆(“,”,$name_数组);
$data=array('id\u merk'=>$this->input->post('id\u merk'),
'photo_barang'=>$names
);
$this->m_barang->post($data);
$this->session->set_flashdata('success','gambar ada');
重定向('admin/merk');
}
}
这就是我的观点
<input class="form-control" name="file[]" id="files" type="file" multiple="multiple">
请帮我解决我的代码问题好吗?首先,只需使用一个循环即可上载多个图像 Second,将
的name属性赋予$this->upload->do_upload()
Third,如果在应用程序文件夹内上载路径,则使用APPPATH.“upload/be/barang”
,如果在应用程序文件夹外,则使用FCPATH.“upload/be/barang”
$count = count($_FILES['file']['size']);
for($s=0; $s<=$count-1; $s++) {
$_FILES['file']['name'] = $_FILES['file']['name'][$s];
$_FILES['file']['type'] = $_FILES['file']['type'][$s];
$_FILES['file']['tmp_name'] = $_FILES['file']['tmp_name'][$s];
$_FILES['file']['error'] = $_FILES['file']['error'][$s];
$_FILES['file']['size'] = $_FILES['file']['size'][$s];
$config['upload_path'] = './upload/be/barang';
$config['allowed_types'] = 'gif|GIF|jpg|JPG|jpeg|JPEG|png|PNG';
$config['max_size'] = '8000';
$config['max_width'] = '1366';
$config['max_height'] = '1024';
$this->load->library('upload', $config);
if(!$this->upload->do_upload('file')){
//image uploading error
}else{
$data = $this->upload->data();
$name_array[] = $data['file_name'];
}
}
$count=count($_FILES['file']['size']);
对于($s=0;$sload->library('upload',$config));
如果(!$this->upload->do_upload('file')){
//图像上传错误
}否则{
$data=$this->upload->data();
$name_数组[]=$data['file_name'];
}
}
到目前为止,您做了哪些尝试和调试工作?为什么要使用两个不同的循环?上一次,我尝试过这样做,这对我来说很有效,但我不知道为什么我的代码不起作用上载多个图像sirI用于上载多个图像,但现在问题是图像上载只有一个sirI,这会导致什么结果ne$count=count($_FILES['file']['size']);
?