I have form with a file input in my CodeIgniter website. When I fill in the form and click the submit button it's working fine. However, when I refresh the browser the same form data is uploaded again. How can I prevent this ?
input form
<form name="image_upload" action="<?= base_url() ?>admin/image_move_upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<ul>
<li class="ui-field"><label for="filename">File Name :</label></li>
<li class="ui-input"><input type="text" name="filename" placeholder=""></li>
<li class="ui-field"><label for="file">Image( *only .jpg) :</label></li>
<li class="ui-input"><input type="file" name="imagefile" value="" placeholder="" required=""></li>
<li><input type="submit" name="Upload" class="ui-submit"></li>
</ul>
</form>
controller section
function image_move_upload() {
$data['errors'] = NULL;
$data['success'] = NULL;
if (isset( $_POST['Upload'] )) {
$config_arr = array(
'upload_path' => './uploads/slider/',
'allowed_types' => 'jpg',
'max_size' => '2048',
'max_width' => '1024',
'max_height' => '768',
'encrypt_name' => true,
'file_name' => 'sanji.jpg',
);
$this->load->library('upload', $config_arr);
if (!$this->upload->do_upload('imagefile')) {
$data['errors'] = $this->upload->display_errors(); // this isn't working
} else {
$data['qs'] = $this->upload->data();
$data['success'] = "File Uploaded Successfully";
}
}
$data['main_content'] = 'admin/upload';
$this->load->view('admin_layout', $data);
}