【问题标题】:Get file path of file uploaded using dropzone获取使用 dropzone 上传的文件的文件路径
【发布时间】:2018-07-18 04:53:06
【问题描述】:

如何在 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
}

【问题讨论】:

    标签: codeigniter dropzone.js


    【解决方案1】:

    希望对您有所帮助:

    上传成功后使用$this-&gt;upload-&gt;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

    【讨论】:

    • 它显示错误 array(1) { ["error"]=> string(43) "您没有选择要上传的文件。" }
    • 但文件正在上传到文件夹
    • 我正在使用 dropzone 表单操作
    • 在你的imageUploadPost方法中使用print_r($_FILES);die;来确保你有文件变量
    • 只显示数组( )
    猜你喜欢
    • 2018-12-11
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多