Check if file is selected for upload to codeigniter

Hi, I have problems downloading part of the file. Well, basically I have a logo output form in which, if the user does not select the logo, he / she can still update his profile, at the same time, the user can also choose to download the logo, but it has some limitations. Now I do not know how I can check this part to find out if it selects an image or not. Here is my code so far in the CI controller:

if (//CHECK IF THERE IS A FILE FOR UPLOAD){ $new_name = $data['id']; $config['upload_path'] = './Logos/'; $config['allowed_types'] = 'jpg|png|gif'; $config['max_size'] = '100'; $config['max_width'] = '100'; $config['max_height'] = '100'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { array_push($data['error_message'], "You have the following errors in your entry:\n"); array_push($data['error_message'], "- Logo must be 100x100 pixels in size not exceeding 100KB with JPG,PNG or GIF format"); array_push($data['error_message'], "\nLogo upload failed."); $data['check_error'] = true; } else { $data = array('upload_data' => $this->upload->data()); //DO UPDATE PART HERE $file = $data['upload_data']['file_name']; rename($config['upload_path'] . $file, $config['upload_path'] .$new_name.'.jpg'); //GO TO SETTINGS $this->load->helper('url'); redirect($data['base'].'settings'); } } 

The part in if is where I would like to set the checks. I tried some tricks, but all of them do not work properly.

Here is my point of view, where if the logo of a certain ID already exists, it simply displays its logo or displays the default logo:

  <tr> <td><p class="titles">Logo</p></td> <td> <div> <input type="text" id="fileName" class="file_input_textbox" readonly="readonly"> <div class="file_input_div"> <input type="button" value="Browse" class="file_input_button" /> <input type="file" class="file_input_hidden" onchange="javascript: document.getElementById('fileName').value = this.value" id="upload" name="userfile" /> </div> </div> </td> </tr> <tr> <td> </td> <td> <p class="titles">100px x 100px jpg, png or gif only.</p> </td> </tr> <tr> <td><p class="titles">Current Logo</p></td> <td> <img src="<?php if(is_array(@getimagesize($base."Logos/".$id.".jpg"))){echo $base."Logos/".$id.".jpg";}else{echo $base."Logos/default.jpg";} ?>" style="margin:0px 0px 0px 90px;"/> </td> </tr> 
+6
source share
1 answer

I usually get my own PHP to check if the file is loading before I get the CI loading class for the job:

 if (isset($_FILES['upload_field_name']) && is_uploaded_file($_FILES['upload_field_name']['tmp_name'])) { //load upload class with the config, etc... $this->load->library('upload', $config); } 
+13
source

All Articles