Hi again,
Im trying to upload a file, in a form defined in xml using JForm, but
the file seems not to be present in JRequest. I'm following this
example
http://docs.joomla.org/How_to_use_the_filesystem_package#Upload_-_Full_Sample,
but I know it's for 1.5.
What I'm doing is trying to save a company's logo, which comes in the
same form as the main data. My controller extends JControllerForm, and
I've overloaded postSaveHook... ¿should file data be there at that
point or should I process before for some reason?
In my form xml the file is defined like this:
<field name="logo" type="file"
class="inputbox validate-file"
label="Logotipo"
required="false"
size="100"
/>
and my controller code is like this:
protected function postSaveHook(JModel &$model, $validData =
array()) {
$file = JRequest::getVar('logo', null, 'files', 'array');
if ($file) {
$filename = JFile::makeSafe($file['name']);
$src = $file['tmp_name'];
$ext = strtolower(JFile::getExt($filename));
if ($ext == 'jpg' || $ext == 'gif' || $ext == 'png') {
$fld = $model->get('nombre');
$dest = JPATH_BASE . DS . 'content' . DS . $fld .
'logo' . $ext;
if (JFile::upload($src, $dest)) {
//TODO: process image.
} else {
$this->setMessage(JText::_('No se ha podido
guardar el logo'), 'error');
}
} else {
$this->setMessage(JText::_('Por favor, utiliza
imágenes de formato jpg, gif o png para el logo.'), 'error');
}
} else if (IW_ENV == IW_DEVELOPMENT) {
$this->setMessage(JText::_('No file received'), 'error');
}
}
And I allways see the "No file received" message...
Any clue?
Thanks!