Welcome Guest, Not a member yet? Register   Sign In
Help not work upload
#1

[eluser]Unknown[/eluser]
I am trying to create a upload using this library

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Img_test {
    
    //function #1 (standart CI)
    function upload($dir_img){

        $CI =& get_instance();
        $CI->load->library('upload');        
        $CI->load->helper('json');

        $config['upload_path']        = './up/'.$dir_img.'/';
        $config['allowed_types']    = 'jpg|jpeg|gif|png';
        $config['max_size']            = '5000';
        $config['max_width']        = '5000';
        $config['max_height']        = '4000';
        $config['encrypt_name']        = 'TRUE';
        $CI->upload->initialize($config);

        if (!$CI->upload->do_upload('userfile')){
            $error = $CI->upload->display_errors();
        }
        
        if ($error) {
            $result['result'] = 'failed';
            $result['error'] = $error;
        } else {
            $result['result'] = 'success';
            $result['size'] = 'Uploaded an image ('.$resarr['file_size'].') with  '.$resarr['image_width'].'px/'.$resarr['image_heigth'].'px.';
        }

        if (!headers_sent() ) {
            header('Content-type: application/json');
        }
        echo json_encode($result);
    }
}

?>

but error "The filetype you are attempting to upload is not allowed."
#2

[eluser]Randy Casburn[/eluser]
Hi Street85,

Is it possible the mime type in the header is mis-matched with the file type? This looks right and the library looks easy enough.

If you are using some odd file type not shown here by chance, you'll need to verify the mimes.php file in the config folder actually has a definition of the mime type in there. It might be wise to check the file anyway just to make sure something isn't wrong with it.

Randy
#3

[eluser]Unknown[/eluser]
THANK YOU!!!!!! worked with
"application/octet-stream"
#4

[eluser]Randy Casburn[/eluser]
You are so very welcome! I'm glad to help.

Take Care, and Welcome to CodeIgniter!

Randy




Theme © iAndrew 2016 - Forum software by © MyBB