简体   繁体   English

使用Codeigniter的文件上传麻烦

[英]File upload trouble using Codeigniter

I can upload files perfectly to uploads folder using Codeigniter on localhost. 我可以使用localhost上的Codeigniter将文件完美地上传到上载文件夹。 However when i try to upload on server i get this error. 但是,当我尝试在服务器上上传时,出现此错误。 I have tried different types of files. 我尝试了不同类型的文件。 txt, .doc .xls .jpg etc, which are all fine on localhost. txt,.doc .xls .jpg等,这些都可以在localhost上正常使用。 i have looked in MIME file and image/jpeg is in for jpeg along with all the other file types i need ('doc' =>'application/msword', etc etc....). 我已经查看了MIME文件,并且image / jpeg和我需要的所有其他文件类型('doc'=>'application / msword'等)一起用于jpeg。 I have checked folder permissions also and they are ok, but it clear im not even getting that far due to the error. 我也检查了文件夹权限,它们还可以,但是由于错误,我很清楚我什至没有走那么远。

Does anyone have any ideas why its not allowing me to upload my files. 有谁知道为什么不允许我上传文件。

    string(57) "The filetype you are attempting to upload is not allowed." array(2) 
    { ["testfile"]=> array(5) 
    { ["name"]=> string(7) "123.jpg" ["type"]=> string(10) "image/jpeg" 
    ["tmp_name"]=> string(14) "/tmp/phpVYtNNs" ["error"]=> int(0) ["size"]=> int(20921) }
    ["quotefile"]=> array(5) 
    { ["name"]=> string(7) "123.jpg" ["type"]=> string(10) "image/jpeg" 
    ["tmp_name"]=> string(14) "/tmp/phpIsvQ7x" ["error"]=> int(0) ["size"]=> int(20921) } } 

Controller: 控制器:

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png|txt|pdf|xls|csv|doc';
    $config['max_size'] = '1000000';
    $config['max_width']  = '100024';
    $config['max_height']  = '76008';
    $this->load->library('upload', $config);

Model: 模型:

    if ( ! $this->upload->do_upload('testfile'))
    {
        var_dump($this->upload->display_errors('', ''));
                    var_dump($_FILES);
        //$error = array('error' => $this->upload->display_errors());
        //echo '<pre>'; print_r($error); echo '</pre>';
        //$this->load->view('upload_form', $error);     
    }
    else
    {
        $data = array('upload_data' => $this->upload->data('testfile'));
        $this->load->view('upload_success', $data);         
    }
    $upload_data = $this->upload->data('testfile');


    if ( ! $this->upload->do_upload('quotefile'))
    {

        $error = array('error' => $this->upload->display_errors());
        echo '<pre>'; print_r($error); echo '</pre>';
        //$this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data('quotefile'));
        $this->load->view('upload_success', $data);
    }

If you are using version 2.1.0, there is a bug in the upload library. 如果您使用的是2.1.0版,则上传库中存在错误。 Refer the below link, it is explained clearly here. 请参考下面的链接,这里对其进行了清晰的说明。

Uploading in Codeigniter - The filetype you are attempting to upload is not allowed 在Codeigniter中上传-不允许您尝试上传的文件类型

you can use my code there 你可以在那里使用我的代码

public function do_tambah_rule()
    {

            $this->load->library('upload');
            $nmfile = "file_".time(); //nama file saya beri nama langsung dan diikuti fungsi time
            $config['upload_path'] = './uploads/'; //path folder
            $config['allowed_types'] = 'pdf|docx'; //type yang dapat diakses bisa anda sesuaikan
            $config['max_size'] = '9072'; //maksimum besar file 3M
            $config['file_name'] = $nmfile; //nama yang terupload nantinya

            $this->upload->initialize($config);

            if($_FILES['file_pembelajaran']['name'] != NULL)
            {
                if ($this->upload->do_upload('file_pembelajaran'))
                {
                    $gbr = $this->upload->data();
                    $data = array(
                      'nama_file' =>$gbr['file_name'],
                      'type_file' =>$gbr['file_type'],
                      'gejala_1' => $this->input->post('gejala_1'),
                        'gejala_2' => $this->input->post('gejala_2'),
                        'gejala_3' => $this->input->post('gejala_3'),
                        'gejala_4' => $this->input->post('gejala_4'),
                        'gejala_5' => $this->input->post('gejala_5'),
                        'id_jurusan'=>$this->session->userdata('id_jurusan'),
                        'id_artikel' => $this->input->post('artikel'),
                        'username' => $this->session->userdata('username'),
                        'hasil' => $this->input->post('hasil')
                    );

                    $this->guru_mod->insert_data('forward_changing',$data); //akses model untuk menyimpan ke database

                    $config2['source_image'] = $this->upload->upload_path.$this->upload->file_name;


                }
            } elseif ($_FILES['file_pembelajaran']['name'] == NULL) {

                $this->session->set_flashdata('pesan', 'File pembelajaran belum di sertakan');
            }

        redirect('guru/daftar_rule','refresh');

    }

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

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