I have an input form in the admin view:
<form name="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file_upload" />
<input type="submit" value="Upload Image" />
<input type="hidden" name="option" value="com_newsshowcase" />
<input type="hidden" name="task" value="upload" />
<?php echo JHtml::_( 'form.token' ); ?>
</form>
This form calls the function upload() in the controller:
public function upload()
{
// Check for request forgeries
JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication()->input;
$file = $app->files->get('file_upload');
$filename = JFile::makeSafe($file['name']);
}
I've been echoing(debugging) the $filename
and the $file
variables, but no value is being echoed. When I echo something like:
echo '<pre>',print_r($file,1),'</pre>';
nothing is echoed. I assume that this means that the file to-be uploaded by this function is not being passed from the view to the controller?
Update: I also imported JInput explicitly (I saw mixed things on this in my searches saying that it isn't necessary, but wouldn't hurt). My original controller extended JController, I tried changing this to JControllerForm and changed the import dependency accordingly and still nothing.
Update #2: When I do a var_dump
on $_POST
I can see the form data, but when I do a var_dump
on $_FILES
it shows an empty array.
Update #3: The size of the image I am trying to upload, as a test, is 345 bytes(super small).
Update #4: I duplicated the form (removed the Joomla specific fields) in a separate stand-alone PHP file that linked to a PHP endpoint that did a var_dump($_FILES)
and it displayed the upload data.
Update #5: Not sure if it matters, but the HTML form resides in the "default_body" section of the admin page.
echo 'Anything';
in that upload function (toward the top), that is showing up, right?