'how to make upload file is optional in codeigniter?
I have some problems. I want to upload file as an optional field, but didnt work with my code. How i can solve this?
controllers
public function zoom_request()
{
$file = ''; // init as blank otherwise notice
if (!empty($_FILES) && !empty($_FILES['file']['name'])) {
$config['upload_path'] = './lampiran/request/';
$config['allowed_types'] = 'pdf|rar|zip|doc|docx|ppt|pptx|jpg|png';
$config['overwrite'] = TRUE;
$config['max_size'] = 10000; //3 * 1024 * 1024; //3Mb; 0=unlimited
$config['max_width'] = 10000; //"3850"; //'1024';
$config['max_height'] = 10000;
$this->upload->initialize($config);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file')) {
redirect('zoom/zoom_request');
}
else {
$media = $this->upload->data();
$inputFileName = './lampiran/complain/' . $media['file_name'];
$data = array(
'id_pegawai' => $this->input->post('id_pegawai'),
'nama_pic' => $this->input->post('nama_pic'),
);
//if the insert data returned true then we show the flash message
if ($this->Zoom_model->add_request($data)) {
$data['flash_message'] = TRUE;
} else {
$data['flash_message'] = FALSE;
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
