У меня возникла проблема с проверкой ограничения размера файла при загрузке файлов в codeigniter.
Вот мой код
public function upload_docu_by_type() {
ini_set('max_execution_time', 300);
$this->load->helper(array('form', 'url'));
$F = array();
$prop_id = sanitize($this->input->post('prop_id'));
$file = sanitize($this->input->post('file'));
$config = array();
$config['upload_path'] = './/assets//img//documents//';
$config['allowed_types'] = 'jpeg|jpg|png|pdf';
$config['max_size'] = '5000';
$config['overwrite'] = TRUE;
$this->load->library('upload');
$files = $_FILES;
for($i=0; $i< count($files['images']['name']); $i++) {
$config['file_name'] = $prop_id."_".$file."_".$i;
// $_FILES['images']['name']= time()."_".$files['images']['name'][$i];
$_FILES['images']['name']= time()."_".preg_replace('/[()]/','',$files['images']['name'][$i]);
// $_FILES['images']['name']= $prop_id."_".$file;
$_FILES['images']['type']= $files['images']['type'][$i];
$_FILES['images']['tmp_name']= $files['images']['tmp_name'][$i];
$_FILES['images']['error']= $files['images']['error'][$i];
$_FILES['images']['size']= $files['images']['size'][$i];
$this->upload->initialize($config);
if (! $this->upload->do_upload('images')){ //if not
$errors = array('error' => $this->upload->display_errors());
$data = array('success' => 0, 'errors' => $errors);
}
else if($_FILES['images']['size'] >= 5000){
$data = array("success" => "1", 'message' => "You've reached the limit");
}else{
$upload_data = $this->upload->data();
$file_name = $upload_data['file_name'];
$file_type = $upload_data['file_type']; //this will be the name of your file
$img = array('uploader_file' => $file_name);
$this->Applicant_model_w->upload_docu_by_type($prop_id,$file_name,$file_type,$file);
$data = array("success" => "1", 'message' => "Successfully uploaded file/s.");
}
}
generate_json($data);
}
Я пытался
else if($_FILES['images']['size'] >= 5000){
$data = array("success" => "1", 'message' => "You've reached the limit");
}
, но этоне работаетЯ просто новичок в Codeigniter.
Как правильно проверить ограничение размера файла?Я использую Code Igniter