Welcome Guest, Not a member yet? Register   Sign In
uploading two files, need to set different file type for each

[eluser]Brad K Morse[/eluser]
I have two fields: image, document

I want to set allowed_types for each field, so image only accepts: jpg|png and document accepts: doc|xls|pdf

I know how to upload both those files from those fields, but I am unsure on how I would set each allowed_types, max_size, etc...

I checked the documentation, but it was not clear.

I assume I will need to create two different config arrays, example: $config_image[], $config_document[]

Then set it like this: $this->load->library('upload', $config_image) and $this->load->library('upload', $config_document)

Then set the appropriate field in $this->upload->do_upload("image")

So in theory:

$image = $this->input->post("image");
$document = $this->input->post("document");

if(!empty($image)) {
  // config_image stuff

  // do_upload for image field

if(!empty($document)) {
  // config_docucment stuff

  // do_upload for document field

I have not tried this, I wanted to see what you thought first, thanks.

Load the library without a config, then use initialize() before each upload, and a clear() after the first one.


if ( ! empty($image))
    $img_config = array(); // Settings here

    // Upload stuff


if ( ! empty($document))
    $doc_config = array(); // Settings here

    // Upload stuff...

Theme © iAndrew 2016 - Forum software by © MyBB