Код: Выделить всё
public function editprojectplans() {
$data = array();
if ($this->isUserLoggedIn) {
$con = array(
'id' => $this->session->userdata('userId')
);
$data['user'] = $this->user->getRows($con);
$id = $this->uri->segment(3);
$data['vals'] = $this->category->selectproject($id);
if (isset($_POST['editproduct'])) {
// Check whether user uploaded pictures
$uploadPath = './uploads/products/';
$width = 1000; // Define width as per your requirement
$height = 1000; // Define height as per your requirement
for ($i = 1; $i processImageUpload($fileInputName, $uploadPath, $width, $height);
}
}
...........................
private function processImageUpload($field, $uploadPath, $width, $height) {
$this->load->library('upload');
$this->load->library('image_lib');
$imageData = array();
$ImageCount = count($_FILES[$field]['name']);
for ($i = 0; $i < $ImageCount; $i++) {
$_FILES['file']['name'] = $_FILES[$field]['name'][$i];
$_FILES['file']['type'] = $_FILES[$field]['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES[$field]['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES[$field]['error'][$i];
$_FILES['file']['size'] = $_FILES[$field]['size'][$i];
// File upload configuration
$config['upload_path'] = $uploadPath;
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$this->upload->initialize($config);
// Upload file to server
if ($this->upload->do_upload('file')) {
// Uploaded file data
$imageData[] = $this->upload->data();
// Resize uploaded image
$path = $imageData[$i]['full_path'];
$config['image_library'] = 'gd2';
$config['source_image'] = $path;
$config['maintain_ratio'] = TRUE;
$config['width'] = $width;
$config['height'] = $height;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
} else {
// Handle upload error
$error = array('error' => $this->upload->display_errors());
// You can log or handle the error as per your application's requirement
}
}
return $imageData;
}
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/78483940/multiple-image-upload-issue-in-codeigniter-php[/url]