简体   繁体   English

CodeIgniter多个上传到2个不同的文件夹

[英]CodeIgniter Multiple Upload to 2 different folder

I am trying to do a multiple file upload where in one input['file'] is for image and another one is for video 我正在尝试上传多个文件,其中一个input['file']用于图像,另一个用于视频

here is the controller 这是控制器

public function upload(){
  $data['errorPic'] = $this->validateUpload();  
  $data['errorVid'] = $this->validateUpload2();
}

public function validateUpload(){
    if ( $_FILES AND isset($_FILES['coverImage']['name']) ){
        $config['upload_path'] = 'blogpics/';
        $config['allowed_types'] = 'png|gif|jpg|jpeg';
        $config['max_size'] = '999999';

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

        if(!$this->upload->do_upload("coverImage")){
            return $this->upload->display_errors();
        }
    }   
}

public function validateUpload2(){
    if ( $_FILES AND isset($_FILES['video']['name'])){
        $config['upload_path'] = 'blogvids/';
        $config['allowed_types'] = 'png|gif|jpg|jpeg';
        $config['max_size'] = '999999';

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

        if(!$this->upload->do_upload("video")){
            return $this->upload->display_errors();
        }
    }
}

only the first function that is called is working 只有第一个调用的功能在起作用

example: if I put first the validateUpload2() Function on the top of validateUpload() function, the first function on the top is working the second one did not 例如:如果我把第一validateUpload2()函数上的顶部validateUpload()函数,顶部的第一功能工作的第二个没

Thanks everyone for the reply 谢谢大家的答复

I already solved it 我已经解决了

I just initialize again the upload using 我只是使用重新初始化上传

$this->upload->initialize();

The reason it is not working is because files uploaded are temporary until moved. 它无法正常工作的原因是因为上传的文件是临时文件,直到被移动。 Once move_uploaded_file is executed, the temporary file is no longer accessible. 一旦执行了move_uploaded_file,该临时文件将不再可访问。 If in the second function you call is_uploaded_file, it will return false. 如果在第二个函数中调用is_uploaded_file,它将返回false。

Look into copying the file you wrote to the first directory to the second folder. 研究将您写入第一个目录的文件复制到第二个文件夹。

Edit 编辑

Looks like you changed your post around. 好像您更改了自己的信息。 That scenario is different from the previous. 这种情况与以前不同。

This time, it looks like there are two separate files being uploaded. 这次,看起来好像有两个单独的文件正在上载。

Looks like it should work, but im looking into it. 看起来它应该工作,但是我正在研究它。 I wonder if it has to do with the reinitialization of the upload helper class. 我想知道是否与上载帮助程序类的重新初始化有关。

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

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