Add File Uploader to Joomla Admin Component
joomla, joomla2.5, model-view-controller, php, xml
Solution
make sure that you have included `enctype="multipart/form-data"` in the form that the file is being submitting. This is a common mistake
/// Get the file data array from the request.
$file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
/// Make the file name safe.
jimport('joomla.filesystem.file');
$file['name'] = JFile::makeSafe($file['name']);
/// Move the uploaded file into a permanent location.
if (isset( $file['name'] )) {
/// Make sure that the full file path is safe.
$filepath = JPath::clean( $somepath.'/'.strtolower( $file['name'] ) );
/// Move the uploaded file.
JFile::upload( $file['tmp_name'], $filepath );}
Problem
I made Joomla admin component according to Joomla guide - http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component In that i need to have file uploader which let user to upload single file. In administrator\components\com_invoicemanager\models\forms\invoicemanager.xml i have defined ``` <field name="invoice" type="file"/> ``` In the controller administrator\components\com_invoicemanager\controllers\invoicemanager.php im trying to retrieve that file like below. But its not working (can't retrieve file) Where am i doing it wrong ? How can i get file and save it on disk ? ``` class InvoiceManagerControllerInvoiceManager extends JControllerForm { function save(){ $file = JRequest::getVar( 'invoice', '', 'files', 'array' ); var_dump($file); exit(0); } } ```