Welcome Guest, Not a member yet? Register   Sign In
Upload validation problem
#1

[eluser]resolv_25[/eluser]
Hi, this seems not to be difficult, but it is not working properly.
I have validation of several input fields, and then the upload field.
Validation of input fields is working fine, if upload item is according to given upload config, it's ok as well, upload is made properly.
When upload item is not defined by config, it shall return error, but it doesn't.
It doesn't make an upload (which is ok), but doesn't return any error, and continue with writing a data into database.

Seems to me that there is a problem when a 2 or more validations are present.
Upload validation without any other is working properly, but not in that case.

Here are the methods in controller:
Code:
function upissonga() {
      
   $this->form_validation->set_rules('artist', 'Artist', 'trim|required');
   $this->form_validation->set_rules('sadrzaj', 'Content', 'trim|required');
   $this->form_validation->set_rules('song', 'Song', 'trim|required');
  
   if ($this->form_validation->run() == FALSE) {
    $data['url'] = "songs/upissonga";
    $data['naslov'] = 'ENTRY OF THE SONG';          
    $data['link'] = '../../';
            
    $this->load->view('songs_view', $data);
}

    else {
       $note1 = 0;  

       // read & upload data, if exits
       if(isset($_FILES['note1']) && !empty($_FILES['note1']['name'])) {
            
           $field_name = "note1";
           $note1 = $_FILES[$field_name]['name'];
           // calling valid_upload method
           $this->valid_upload($field_name);
        }
            
         // validation ok, let's write data
        $song = array('artist' => $this->input->post('artist'),
                  'album' => $this->input->post('album'),
                  'song' => $this->input->post('song'),
                  'sadrzaj' => $this->input->post('sadrzaj'),
                  'napomena' => $this->input->post('napomena'),
                  'note1' => $note1    );
        
        $this->songsmodel->unos($song);
        redirect('../','refresh');
      }
}

function valid_upload($field_name) {
        
    $config['upload_path'] = './note/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg';
    $config['max_size'] = '250';
    $config['max_width'] = '1240';
    $config['max_height'] = '1750';
    $config['image_library'] = 'gd2';
        
    $this->load->library('upload', $config);
        
    if (! $this->upload->do_upload($field_name)) {
        // return data in form
        $data['artist'] = $this->input->post('artist');
        $data['album'] = $this->input->post('album');
        $data['song'] = $this->input->post('song');
        $data['sadrzaj'] = $this->input->post('sadrzaj');
        $data['napomena'] = $this->input->post('napomena');
            
        $data['error'] = $this->upload->display_errors();
            
        $this->load->view('songs_view', $data);
    }    
    else {
        $data = array('upload_data' => $this->upload->data($field_name));
    }
}
In view I have this:
Code:
...
...
<?php
echo form_open_multipart($url);
if(isset($error)) {
   echo $error;
}
?>
...
</form>
etc.




Theme © iAndrew 2016 - Forum software by © MyBB