【发布时间】:2012-10-07 07:21:14
【问题描述】:
续。 - Add File Uploader to Joomla Admin Component
我可以上传文件并将其保存在磁盘上。但它没有在数据库中保存文件名。
我该怎么做?
这是控制器 -
class InvoiceManagerControllerInvoiceManager extends JControllerForm
{
function save(){
$file = JRequest::getVar('jform', null, 'files', 'array');
$path = JPATH_BASE;
// Make the file name safe.
jimport('joomla.filesystem.file');
$file['name']['invoice'] = JFile::makeSafe($file['name']['invoice']);
// Move the uploaded file into a permanent location.
if (isset($file['name']['invoice'])) {
// Make sure that the full file path is safe.
$filepath = JPath::clean($path. DS ."components". DS ."com_invoicemanager". DS ."files". DS .strtolower($file['name']['invoice']));
// Move the uploaded file.
JFile::upload( $file['tmp_name']['invoice'], $filepath );
}
return parent::save();
}
}
XML 中的表单字段 -
<field name="invoice" type="file"/>
更新: 添加从@Andras Gera 代码中获取的以下行后工作
$data = JRequest::getVar( 'jform', null, 'post', 'array' );
$data['invoice'] = strtolower( $file['name']['invoice'] );
JRequest::setVar('jform', $data );
【问题讨论】:
标签: php file-upload joomla joomla2.5