In addition to @Bakual's answer, let's assume you a simple form like so:
<form name="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file_upload">
</form>
To upload the file once the submit button has been pressed, you can use this:
$input = JFactory::getApplication()->input;
$file = $input->files->get('file_upload');
// Cleans the name of teh file by removing weird characters
$filename = JFile::makeSafe($file['name']);
$src = $file['tmp_name'];
$dest = JPATH_BASE . '/modules/mod_mymodule/' . $filename;
if (JFile::upload($src, $dest))
{
// The file has successfully been uploaded :)
}
else
{
// Oh crap, something happened. Run!
}
You will obviously need to change the path ($dest
) to whatever suits your needs.
There is a load of validations you should perform when handling uploads, a lot of which can be found on the link you have been provided with already:
http://docs.joomla.org/How_to_use_the_filesystem_package
File upload with restrictions, allowing only specific file extentions.
an error you're getting with your current code? If so, please show you current codeJRequest
so simply replace with yourJInput
code: docs.joomla.org/How_to_use_the_filesystem_package