Ma il campo file effettua l'upload o devo effettuarlo io?
in ogni caso ecco il codice che ho scritto:
edit.php
<form action="<?php echo JRoute::_('index.php?option=com_courses&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="material-form" class="form-validate" enctype="multipart/form-data">
<div class="width-60 fltlft">
<fieldset class="adminform">
<legend><?php echo empty($this->item->id) ? JText::_('COM_COURSES_MATERIALS_NEW') : JText::sprintf('COM_COURSES_MATERIALS_EDIT', $this->item->id); ?></legend>
<ul class="adminformlist">
<li><?php echo $this->form->getLabel('title'); ?>
<?php echo $this->form->getInput('title'); ?></li>
<li><?php echo $this->form->getLabel('file'); ?>
<?php echo $this->form->getInput('file'); ?></li>
miomodel.xml
<field name="file" type="file"
class ="inputbox"
label="JGLOBAL_TITLE"
description="COM_COURSES_FIELD_TITLE_DESC"/>
miomodel.php:
public function save($data){
$file = JRequest::getVar('jform_file', null, 'files', 'array');
JFactory::getApplication()->enqueueMessage( 'var: ' . $file);
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
JFactory::getApplication()->enqueueMessage( 'filename: ' . $file);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = JPATH_COMPONENT . DS . "folder" . DS . $filename;
//First check if the file has the right extension, we need jpg only
if ( strtolower(JFile::getExt($filename) ) == 'jpg') {
if ( JFile::upload($src, $dest) ) {
JFactory::getApplication()->enqueueMessage( 'upload successfull');
//Redirect to a page of your choice
} else {
JFactory::getApplication()->enqueueMessage( 'upload failed');
//Redirect and throw an error message
}
} else {
JFactory::getApplication()->enqueueMessage( 'wrong extension');
//Redirect and notify user file is not right extension
}
parent::save($data);
}
io credo di sbagliare sulla save, in quanto la variabile $file risulta essere vuota....