dragon7088 2016-07-27 14:45
浏览 29
已采纳

如何修复上传文件的不需要的双重副本?

My code is running fine and adding the files correctly but it is adding one additional copy of uploaded file. What is wrong?

My controller is like this:

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');
        }
    }
  • 写回答

1条回答 默认 最新

  • duannuochi3549 2016-07-27 16:19
    关注

    ... but it is adding one additional copy of uploaded file. What is wrong?

    That's because you're calling do_upload() twice...

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

    Since you may need the conditional logic that handles upload failures, delete the first instance of do_upload().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应