Admin Component File Upload -> Cannot Get JInput to work

by Zachary Draper   Last Updated March 28, 2018 20:10 PM

I am struggling to get an admin form file upload to work using JInput. I have tried pretty much every permutation of $input->files->get(''); I can think of with no luck. No matter what I do, it always returns an empty array. If I print the contents of the $input object, I can see the file data. Similarly, if I print the contents of the $_FILES super variable I can see the file data. So I know it is uploading correctly, the problem becomes how can I use Joomla! standards to work with those files?

Here is the PHP in the save() function of my model:

$input = JFactory::getApplication()->input;
print_r($input->files); // this shows the files data
// $code_file = $input->files->get('jform'); // an example of what I've tried
// $code_file = $input->files->get('jform[code_file]');
// $code_file = $input->files->get("jform['code_file']");
$code_file = $input->files->get('code_file');
print_r($code_file); // this always returns an empty array
die();

I have defined the form field as follows:

<!-- code_file -->
<field
  accept=".xlsx"
  description="COM_CUSTOM_FORM_CODE_FILE_DESC"
  label="COM_CUSTOM_FORM_CODE_FILE_LBL"
  name="code_file"
  type="file" />

That filed is then used in the view. Here is the output HTML (abbreviated for simplicity):

<form action="<?php echo JRoute::_('index.php?option=com_custom&layout=edit&id=' . (int) $this->item->id); ?>" method="post" enctype="multipart/form-data" name="adminForm" id="my-form" class="form-validate">
...
    <input type="file" name="jform[code_file]" id="jform_code_file" accept=".xlsx" aria-invalid="false">
...
</form>

Where am I going wrong?



Related Questions


Custom Component - JInput Isn't Getting the Form Input

Updated October 09, 2016 09:04 AM

Joomla 3.4 Development File Handling

Updated April 03, 2015 21:21 PM

joomla 3.x component for uploading image-file

Updated May 19, 2016 07:46 AM