I cant find out why Joomla is not allowing to upload images through .xml created form.
I have a field for file upload
<field name="nuotrauka" type="file"
label="COM_DALYVIAI_FORM_LBL_DALYVIS_NUOTRAUKA"
description="COM_DALYVIAI_FORM_DESC_DALYVIS_NUOTRAUKA"
upload_directory="/images/"
accept="image/*" />
After form submit I get error: "Error: This filetype is not allowed"
I tried .jpg, .png filetypes.
The issue is the Joomla file field is nothing more but a means to generate the form fields to select a file. This means there is no built in logic in the core to handle file submissions server side when a form is submitted. You would need to add logic to your components controller to grab the info from the request and save it where needed. I pasted a sample method from a project's controller that required file uploads.
public function upload() {
//JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$jinput = JFactory::getApplication()->input;
jimport('joomla.filesystem.file');
// We're putting all our files in a directory called images.
$path = 'images/uploaded/';
// The posted data, for reference
$file = $jinput->get('value', '', 'string');
$name = $jinput->get('name', '', 'string');
// Get the mime
$getMime = explode('.', $name);
$mime = end($getMime);
// Separate out the data
$data = explode(',', $file);
echo "<h1>" . $path . $name . "</h1>";
// Encode it correctly
$encodedData = str_replace(' ','+',$data[1]);
$decodedData = base64_decode($encodedData);
//if (JFile::upload($decodedData, $path . $name)) {
if(file_put_contents($path . $name, $decodedData)) {
JError::raiseNotice(null, $name . ": uploaded successfully");
} else {
// Show an error message should something go wrong.
JError::raiseError(null, "Something went wrong. Check that the file isn't corrupted");
}
}
If you've already written the server side file upload controller method and you've confirmed all the other suggestions are not the issue, you should include the code in your question as chances are that's where the error is occurring.