我的codeigniter照片库只需点击一下即可上传多张图片。图像上传时带有加密名称,但名称保存在数据库原始图像名称中。我想在数据库中保存这些加密名称。
我的控制器代码是:
public function file_upload2(){
if($this->session->userdata('is_loged_in')){
$config = array();
$config['image_library'] = 'gd2';
$config['upload_path'] = './photo/'; //give the path to upload the image in folder
$config['allowed_types'] = 'gif|jpg|png|jpeg|JPG';
$config['max_size'] = 0;
$config['maintain_ratio'] = FALSE;
$config['encrypt_name'] = TRUE;
$config['overwrite'] = TRUE;
$this->form_validation->set_rules('category', 'Category', 'required|trim');
if ($this->form_validation->run() == TRUE){
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++){
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($config);
$this->upload->do_upload();
$fileName = $_FILES['userfile']['name'];
$images[] = $fileName;
}
$category = $this->input->post('category');
$fileName = implode(',',$images);
$this->Upload_model->upload_image($fileName,$category);
if($this->upload->do_upload()){
$this->success();
} else {
$this->index();
}
} else {
$this->index();
}
} else {
redirect('admin');
}
}
我的模特:
public function upload_image($fileName,$category){
if($fileName!='' ){
$filename1 = explode(',',$fileName);
foreach($filename1 as $file){
$file_data = array(
'name' => $file,
'datetime'=> date('Y-m-d h:i:s'),
'category'=> $category
);
$this->db->insert('photo', $file_data);
}
}
}
答案 0 :(得分:0)
上传时,请使用codeigniter的上传数据,因为php value
数组对加密名称一无所知:
show(val)
{
console.log(val.target);
this.value = true;
this.valueChange.emit(true);
}
hide()
{
console.log('hide');
this.value = false;
this.valueChange.emit(false);
}