【问题标题】:how to fix unwanted double copy of uploaded file?如何修复不需要的上传文件的双重副本?
【发布时间】:2016-07-27 14:45:00
【问题描述】:

我的代码运行良好并正确添加了文件,但它正在添加一个额外的上传文件副本。怎么了?

我的控制器是这样的:

public function add_audio(){

            $config['upload_path'] = './musics/';
            $config['allowed_types'] = 'mp3';
            $config['max_size'] = '999999999999999999999';

            $this->load->library('upload',$config);
            $this->upload->do_upload();



    if ( ! $this->upload->do_upload())
        {
            $data['error'] = $this->upload->display_errors();
            print_r($data['error']);    
            //line of codes that displays if there are errors
        }
    else
    {
        $data['audio'] = $_FILES['userfile']['name'];

        $this->load->model('main');
        $query = $this->main->insert('audio',$data);

        if($query == TRUE){
            $this->load->view('admin/success');
        }
    }

【问题讨论】:

    标签: php codeigniter file-upload codeigniter-3


    【解决方案1】:

    ...但它正在添加一个额外的上传文件副本。怎么了?

    那是因为你调用了两次do_upload()...

    public function add_audio() 
    {
        ....
    
        $this->upload->do_upload(); // <- FIRST upload (remove this one)
    
        if ( ! $this->upload->do_upload() ) // <- SECOND upload
        {
            ....
    

    由于您可能需要处理上传失败的条件逻辑,请删除do_upload() 的first 实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多