我是 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 );
来更新数据库值。但是文件路径没有进入列。
我的表单结构是:-
<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>