我在控制器中有2个功能。
这只会在db中插入一个图像的路径。如果我从回调函数中回显print_r,它会显示所有图像,但仅来自验证函数。
// Some Validation
} else {
$this->fileupload_check();
$data['uploadedimage'] = $this->upload->data();
$image_name = $data['uploadedimage']['file_name'];
//echo '<pre>';
//print_r($this->upload->data());
$data['uploadedimage'] = $image_name;
$this->load->model('admin/model_users');
if($query = $this->model_users->insert_property_details($data)) {
redirect('dashboard/property-successfully-posted');
}
回调图片上传:
public function fileupload_check() {
$number_of_files = sizeof($_FILES['uploadedimages']['tmp_name']);
$files = $_FILES['uploadedimages'];
for($i=0;$i<$number_of_files;$i++) {
if($_FILES['uploadedimages']['error'][$i] != 0) {
$this->form_validation->set_message('fileupload_check', 'At least 1 image needs to be uploaded in jpeg, png or gif format only.');
return FALSE;
}
}
$this->load->library('upload');
$config['upload_path'] = FCPATH . 'uploads/';
$config['allowed_types'] = 'gif|jpg|png';
for ($i = 0; $i < $number_of_files; $i++) {
$_FILES['uploadedimage']['name'] = $files['name'][$i];
$_FILES['uploadedimage']['type'] = $files['type'][$i];
$_FILES['uploadedimage']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['uploadedimage']['error'] = $files['error'][$i];
$_FILES['uploadedimage']['size'] = $files['size'][$i];
$this->upload->initialize($config);
if ($this->upload->do_upload('uploadedimage')) {
$data['uploadedimage'] = $this->upload->data();
$image_name = $data['uploadedimage']['file_name'];
$data['uploadedimage'] = $image_name;
} else {
$this->form_validation->set_message('fileupload_check', $this->upload->display_errors());
return FALSE;
}
}
return TRUE;
}
我试图传递来自“回拨图片上传”的价值&#39;功能到验证功能但它只传递一个图像而不是所有选择的图像。
答案 0 :(得分:0)
试试这个编码...
public function fileupload_check() {
$Error_bool = TRUE;
$Error = '';
$number_of_files = sizeof($_FILES['uploadedimages']['tmp_name']);
$files = $_FILES['uploadedimages'];
for($i=0;$i<$number_of_files;$i++) {
if($_FILES['uploadedimages']['error'][$i] != 0) {
$Error_bool = FALSE;
$Error = 'At least 1 image needs to be uploaded in jpeg, png or gif format only.';
}
}
$this->load->library('upload');
$config['upload_path'] = FCPATH . 'uploads/';
$config['allowed_types'] = 'gif|jpg|png';
for ($i = 0; $i < $number_of_files; $i++) {
$_FILES['uploadedimage']['name'] = $files['name'][$i];
$_FILES['uploadedimage']['type'] = $files['type'][$i];
$_FILES['uploadedimage']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['uploadedimage']['error'] = $files['error'][$i];
$_FILES['uploadedimage']['size'] = $files['size'][$i];
$this->upload->initialize($config);
if ($this->upload->do_upload('uploadedimage')) {
$data['uploadedimage'] = $this->upload->data();
$image_name = $data['uploadedimage']['file_name'];
$data['uploadedimage'] = $image_name;
} else {
$Error_bool = FALSE;
$Error = $this->upload->display_errors();
}
}
if($Error_bool == FALSE) {
$this->form_validation->set_message('fileupload_check', $Error);
return FALSE;
} else {
return TRUE;
}
}
答案 1 :(得分:0)
最简单的方法是创建一个serialcodes_id
并在其中发送session
并在另一个函数中访问该会话。
如果你想破坏会话
,你可以在之后销毁会话答案 2 :(得分:0)
我必须对其进行一些更改才能使其正常工作,
这也有助于另外一件事。之前在表单验证错误的情况下,错误图像被上传到上传文件夹,但现在他们没有。
可以在SOLVED
找到整个脚本