简体   繁体   English

codeigniter两个不同的file_upload需要两个不同的配置

[英]codeigniter two different file_upload need two different configs

Yup. 对。 The title says it all. 标题说明了一切。 I have two file upload functions in a view and they need two different configs to upload files. 我在视图中有两个文件上传功能,它们需要两个不同的配置来上传文件。

echo form_label('Product Image') . form_upload('prod_image','');
echo form_label('Product Manual') . form_upload('prod_manual','');

As the names imply, the first upload form should contain only an image file and upload it to an image folder. 顾名思义,第一个上载表单应该只包含一个图像文件,然后将其上载到图像文件夹。 The other should contain only a doc/pdf file and upload it to a manual folder. 另一个应仅包含doc / pdf文件,并将其上传到手动文件夹。

In a controller, how can I give them two different configs? 在控制器中,如何给他们两个不同的配置? I can't find any info regarding it 我找不到有关它的任何信息

Thank you in advance! 先感谢您!

//open single form is enough and target to this method update the form field name appropriate to the document and image //打开单个表单就足够了,此方法的目标为更新适用于文档和图像的表单字段名称

//controlleer method
function do_upload()
{
 //upload image
  if($this->upload_image('field_name'))
  {
    //upload dsuccess
  }else{
     //error
  }

  //upload image
  if($this->upload_document('field_name'))
  {
    //upload dsuccess
  }else{
     //error
  }

}

//controlleer method
function upload_image($form_field_name)
{

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';

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

    if ( ! $this->upload->do_upload($form_field_name))
    {
    return false;
    }
    else
    {
       return true;
    }
}

//controlleer method
function upload_document($form_field_name)
{

    $config['upload_path'] = './uploads/';
   $config['allowed_types'] = 'doc|pdf';

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

    if ( ! $this->upload->do_upload($form_field_name))
    {
    return false;
    }
    else
    {
       return true;
    }
}

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

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