Codeigniter multiple file upload paths

后端 未结 3 1456
春和景丽
春和景丽 2021-01-06 17:05

I\'m building an app which needs to take uploaded files and put them in separate directories for thumbnails and fullsize images. But $config[\'upload_path\'] = \'./uploads/\

3条回答
  •  独厮守ぢ
    2021-01-06 17:59

    Actually all you need to do is "re-initialize" the upload class. Codeigniter does not allow you to call the class twice with new parameters (it ignores the second request), however you can tell the class to manually load new parameters. Here are the basics: (notice the line "$this->upload->initialized($config)" This is the key.

    // this is for form field 1 which is an image....
    $config['upload_path'] = './uploads/path1';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
    $this->upload->initialize($config); 
    $this->upload->do_upload($fieild_1);
    
    // this is for form field 2 which is a pdf
    $config['upload_path'] = './pdfs/path2';
    $config['allowed_types'] = 'pdf';
    $config['max_size'] = '300';
    $this->upload->initialize($config); 
    $this->upload->do_upload($fieild_2);
    

    I wrote an entire article about it here: http://taggedzi.com/articles/display/multiple-file-uploads-using-codeigniter

    You can change any of the allowed parameters in your second initialize script so that your second file can be of a completely different makeup. You can do this as many times as you like you just have to re-initialized for each file type. (You can even setup a config array and loop through if you like...)

    Hope this helps.

提交回复
热议问题