0

I am trying to upload a single or array of files and am not sure how to use the jinput with the array and filter. Tried multiple suggestions from here and documentation and cannot make it work for me.

// Get some data from the request
$file       = JRequest::getVar('file', '', 'files', 'array');
$file_id    = $this->input->get('file_id');
$folder     = $this->input->getString('folder');
$filter     = new JFilterInput();
$folder     = $filter->clean($folder, 'path');

Appreciate any suggestions.

1

1 Answer 1

1

Use this:

$this->input->files->get('file', [], 'array');

Note that returned data is formatted differently to allow iterating over files:

array(2) {
  [0]=>
  array(5) {
    ["name"]=>
    string(16) "joomla_black.png"
    ["type"]=>
    string(9) "image/png"
    ["tmp_name"]=>
    string(23) "C:\wamp\tmp\php5788.tmp"
    ["error"]=>
    int(0)
    ["size"]=>
    int(4979)
  }
  [1]=>
  array(5) {
    ["name"]=>
    string(14) "powered_by.png"
    ["type"]=>
    string(9) "image/png"
    ["tmp_name"]=>
    string(23) "C:\wamp\tmp\php5798.tmp"
    ["error"]=>
    int(0)
    ["size"]=>
    int(3197)
  }
}

As opposed to having an array with properties as keys when using JRequest:

array(5) {
  ["name"]=>
  array(2) {
    [0]=>
    string(16) "joomla_black.png"
    [1]=>
    string(14) "powered_by.png"
  }
  ["type"]=>
  array(2) {
    [0]=>
    string(9) "image/png"
    [1]=>
    string(9) "image/png"
  }
  ["tmp_name"]=>
  array(2) {
    [0]=>
    string(23) "C:\wamp\tmp\php5788.tmp"
    [1]=>
    string(23) "C:\wamp\tmp\php5798.tmp"
  }
  ["error"]=>
  array(2) {
    [0]=>
    int(0)
    [1]=>
    int(0)
  }
  ["size"]=>
  array(2) {
    [0]=>
    int(4979)
    [1]=>
    int(3197)
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.