获取使用dropzone上传的文件的文件路径

时间:2018-07-18 04:53:06

标签: codeigniter dropzone.js

如何在CodeIgniter中获取使用dropzone上传的文件的文件路径?

我的查看页面是

 <form action="<?php echo site_url('Upload/imageUploadPost');?>" class="dropzone" id="my-awesome-dropzone" enctype="multipart/form-data" method="post">
                                <div class="fallback">
                                    <input name="userfile" type="file"/>
                                </div>
</form>

我的控制器是

public function imageUploadPost()
    {

                $config['upload_path']   = './uploads/'; 
        $config['allowed_types'] = 'gif|jpg|png'; 
        $config['max_size']      = 1024;


                $this->load->library('upload', $config);
        $this->upload->do_upload('file');
//here I need to fetch the uploaded file details like name ,path
}

1 个答案:

答案 0 :(得分:0)

希望这对您有帮助:

上传成功后使用$this->upload->data();来获取文件详细信息,您的方法应如下:::

public function imageUploadPost()
{
    //print_r($_FILES);die;
    $config['upload_path']   = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size']      = 1024;
    $this->load->library('upload', $config);
    if ($this->upload->do_upload('userfile'))
    {
        $data = array('upload_data' => $this->upload->data());
        /* for full file path use $data['full_path'] and so like this */
        $file_path = $data['full_path'];
        echo $file_path ;
        var_dump($data);
        die();  
    }
    else
    {
        $error = array('error' => $this->upload->display_errors());
        var_dump($error);
        die();
    }
}

更多信息:https://www.codeigniter.com/user_guide/libraries/file_uploading.html