I have a field in my form that has a file type. When the user clicks on the save icon, I naturally want to upload the file to the server and save the file name in the database. I tried to verify this by repeating the file name, but it does not seem to work. Also, how to add a file name to the database? Is this done in the model? Thank!
Controllers / customcom.php
jimport('joomla.filesystem.file');
class CustomComControllerCustomCom extends JControllerForm
{
function save()
{
$file = JRequest::getVar('img_url', null, 'files', 'array');
$filename = JFile::makeSafe($file['name']);
echo $filename;
}
}
models / forms / customcom.xml
<?xml version="1.0" encoding="utf-8"?>
<form enctype="multipart/form-data">
<fieldset>
<field
name="img_url"
type="file"
label="Image upload"
description=""
size="40"
class="inputbox"
default=""
/>
</fieldset>
</form>
source
share