简体   繁体   English

如何使用php上传和保存qif文件

[英]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 我正在尝试在php codeigniter中上传.qif文件,但返回错误

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. 当我尝试上传其他类型的文件(PDF,CSV,文档等)时,他们成功上传了。

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函数,它可以正常工作

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: 您收到“不允许使用文件类型”错误,因为原始的Codeigniter MIME类型配置文件未列出qif条目:

in your config/mimes.php file add to the $mimes array this line: 在您的config/mimes.php文件中, config/mimes.php添加到$mimes config/mimes.php数组中:

'qif'   =>  'application/qif'

and eventually 最终

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

mime-type source: http://fileformats.archiveteam.org/wiki/Ext:qif MIME类型来源: http//fileformats.archiveteam.org/wiki/Extqif

the native php move_uploaded_file method without checking for mime-types can turn into a security problem 不检查mime类型的本机php move_uploaded_file方法会变成安全问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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