我是joomla的新手,我正在使用2.5.14版本。我需要从后端上传文件,因为我创建了表单和所有。我的功能保存是:
function save(){
$row =& JTable::getInstance('exmps', 'Table');
if(!$row->bind(JRequest::get('post')))
{
JError::raiseError(500, $row->getError() );
}
jimport( 'joomla.filesystem.folder' );
jimport('joomla.filesystem.file');
if ( !JFolder::exists( JPATH_COMPONENT_ADMINISTRATOR.DS."downloads" ) ) {
JFolder::create( JPATH_COMPONENT_ADMINISTRATOR.DS."downloads" );
}
$file = JRequest::getVar( 'uploaded', null, 'files', 'array' );
$filename = JFile::makeSafe($file['name']);
if ( $filename != '' ) {
$filepath = JPath::clean(JPATH_COMPONENT_ADMINISTRATOR.DS."downloads". DS . strtolower( $filename ) );
JFile::upload( $file['tmp_name'], $filepath );
}
$row->name = JRequest::getVar( 'name', '','post', 'string', JREQUEST_ALLOWRAW );
$row->ordering=JRequest::getVar( 'ordering', '','post', 'string', JREQUEST_ALLOWRAW );
$row->publish_up=JRequest::getVar( 'publish_up', '','post', 'string', JREQUEST_ALLOWRAW );
$row->uploaded=JRequest::getVar( 'uploaded', '','post', 'path', JREQUEST_ALLOWRAW );
if(!$row->store()){
JError::raiseError(500, $row->getError() );
}
$link='index.php?option=com_exmp'.'&task=edit&cid[]='.$row->id;
$app = JFactory::getApplication();
$app->redirect($link,'Tender Successfully Saved', 'message');
}
在选择文件并单击“保存”后,我收到此错误Warning: Failed to move file!
。
此外,我使用此行$row->uploaded=JRequest::getVar( 'uploaded', '','post', 'path', JREQUEST_ALLOWRAW );
更新db值。但文件路径未进入列。
我的表单结构是: -
<form action="" method="post" name="adminForm" enctype="multipart/form-data">
<table class="admintable">
<?php echo'<br><br>'?>
<tr><td>
<label for="name">
<?php echo JText::_( 'Name' ); ?>:</label></td>
<td>
<input type="textbox" name="name" value="<?php echo $row->name?>" size="30" class="inputbox"/>
</td>
</tr>
<tr><td><label for="ordering">
<?php echo JText::_( 'Ordering' ); ?>:</label></td>
<td>
<input type="textbox" name="ordering" value="<?php echo $row->ordering?>" size="30" class="inputbox"/>
</td>
</tr>
<tr><td><label for="publish">
<?php echo JText::_( 'Published Date' ); ?>:</label></td>
<td>
<input type="textbox" name="publish_up" value="<?php echo $row->publish_up?>" size="30" class="inputbox"/>
</td>
</tr>
<tr><td><label for="filename">
<?php echo JText::_( 'Upload file' ); ?>:</label></td>
<td>
<input type="file" name="uploaded" value="<?php echo $row->uploaded?>" size="30" class="inputbox"/>
</td>
</tr>
<tr><td><label for="description">
<?php echo JText::_( 'Description' ); ?>:</label></td>
<td >
<?php
echo $editor->display('description',$row->description,'100%','250','40','6',false);
?>
</td>
</tr>
</table>
<input type="hidden" name="option" value="com_tenders" />
<input type="hidden" name="id" value="<?php echo $row->id?>" />
<input type="hidden" name="cid[]" value="<?php echo $row->id?>" />
<input type="hidden" name="task" value="" />
</form>