0

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?

0

This should work. It if don't then pls post more code.

$input = JFactory::getApplication()->input;
$all_files = $input->files->get('jform');
$code_file = $all_files['code_file'];
print_r($code_file);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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