0

I'm having a bit of a headache trying to get Uploadify working with Codeigniter. Basically what i'm trying to do is upload multiple files and then run a db query to add it's details to my db. I am going to add more sophisticated code later (like getting EXIF/IPTC data), but for now I just need it to grab the filename and insert into the db for each photo after it's uploaded.

Trouble is i'm getting a HTTP 302 error. I've set this:

$config['sess_match_useragent'] = FALSE;

And I also put the following in my .htaccess file:

SecFilterEngine Off
SecFilterScanPOST Off

But it caused the entire site to stop working, throwing up an 'Internal server error'.

I really want uploadify to work, it's great, just a bit of a nightmare with Codeigniter!

My code is below:

Input in my view:

<input id="fileInput" name="fileInput" type="file" />
     <script type="text/javascript">
        $(document).ready(function() {
        $("#fileInput").uploadify({
            'uploader'       : '<?php echo base_url()?>assets/uploadify/uploadify.swf',
            'script'         : '<?php echo site_url()?>/upload/do_upload/',
            'cancelImg'      : '<?php echo base_url()?>assets/uploadify/cancel.png',
            'fileExt'        : '*.jpg;*.jpeg',
            'folder'         : 'assets/photos/highres',
            'auto'           : true,
            'multi'          : true,
            'onError'        : function (event,ID,fileObj,errorObj) {
                          alert(errorObj.type + ' Error: ' + errorObj.info);
                        }
        });    });

    </script>

My controller:

public function do_upload()
        {
            // check for login, if logged in
            if($this->session->userdata('logged_in') == "1")
            {
                $config['upload_path'] = 'assets/photos/highres/';
                $config['allowed_types'] = 'jpg';
                $config['max_size'] = '1000000';
                $config['overwrite'] = FALSE;
                $config['remove_spaces'] = TRUE;
                $config['encrypt_name'] = FALSE;

                $this->load->library('upload', $config);

                if(! $this->upload->do_upload('Filedata'))
                {
                    echo $this->upload->display_errors();
                }
                else
                {
                   $errors = $this->upload->display_errors();

                   $upload_info = $this->upload->data();

                   // Insert file information into database
                   $data = array(
                                    'id' => NULL,
                                    'filename' => $upload_info['file_name']
                                );
                   $this->db->insert('photos', $data);
                  }
            } 
            else
            {
                // redirect to signin page if not logged in
                redirect('signin');
            }
        }

Any help is most appreciated!

1 Answer 1

2

change files /application/config/mimes.php add

'application/octet-stream'

on

'jpeg'  =>  array('image/jpeg', 'image/pjpeg'),
'jpg'   =>  array('image/jpeg', 'image/pjpeg'),
'jpe'   =>  array('image/jpeg', 'image/pjpeg'),
'png'   =>  array('image/png',  'image/x-png'),

and finally the mimes like this

'jpeg'  =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpg'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'jpe'   =>  array('image/jpeg', 'image/pjpeg', 'application/octet-stream'),
'png'   =>  array('image/png',  'image/x-png', 'application/octet-stream'),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.