简体   繁体   中英

how to upload and save qif file using php

I am trying to upload a .qif file in php codeigniter but it returns an error

The filetype you are attempting to upload is not allowed.

When I try to upload another type file (PDF, CSV, docs, etc.) they upload successfully.

Here is my code:

function do_upload($field_name, $files, $folder_path,$save_name="",$prefix="bk_"){
    $ci =   & get_instance();
    //create upload folder if not exists
    if (!is_dir($folder_path)) {
        mkdir($folder_path, 0777, TRUE);
    }
    $save_name =   $prefix.time()."_".$files['name'];
    $data                       =   array();
    $config                     =   array();
    $config['upload_path']      =   $folder_path;
    //$config['max_size']         =   0;

    $config['allowed_types'] = 'csv|CSV|txt|TXT|pdf|PDF|zip|ZIP|doc|DOC|docx|DOCX|xlsx|xls|XLS|XLSX|QIF|qif';
    $config['file_name']    =   $save_name;
    $ci->load->library('upload');
    $ci->upload->initialize($config);
//    echo "hello 1"; die;
    if ($ci->upload->do_upload($field_name)){
        $data           =   $ci->upload->data();
        $data['status']    =   1;
    }
    else{
        $data['status']    =   0;
        $data['error']  =   $ci->upload->display_errors();
    }
    return $data;
}

I got a solution after lot of searches I just use move_uploaded_file function and it's work

move_uploaded_file($_FILES["file"]["tmp_name"], $path);

if someone have a better answer answer please share that.

thanks

You get the "filetype is not allowed" error, because the original Codeigniter mime-type configuration file doesn't list an qif entry:

in your config/mimes.php file add to the $mimes array this line:

'qif'   =>  'application/qif'

and eventually

'qif'   =>  'image/x-quicktime'

mime-type source: http://fileformats.archiveteam.org/wiki/Ext:qif

the native php move_uploaded_file method without checking for mime-types can turn into a security problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM