将文件上传器添加到Joomla管理组件 [英] Add File Uploader to Joomla Admin Component
问题描述
我根据Joomla指南制作了Joomla管理组件- http://docs. joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component
I made Joomla admin component according to Joomla guide - http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component
在这种情况下,我需要具有允许用户上传单个文件的文件上传器.
In that i need to have file uploader which let user to upload single file.
在我已定义的administrator \ components \ com_invoicemanager \ models \ forms \ invoicemanager.xml中
In administrator\components\com_invoicemanager\models\forms\invoicemanager.xml i have defined
<field name="invoice" type="file"/>
在控制器Administrator \ components \ com_invoicemanager \ controllers \ invoicemanager.php中,我试图像下面那样检索该文件.但它不起作用(无法检索文件)
In the controller administrator\components\com_invoicemanager\controllers\invoicemanager.php im trying to retrieve that file like below. But its not working (can't retrieve file)
我在哪里做错了?
我如何获取文件并将其保存在磁盘上?
How can i get file and save it on disk ?
class InvoiceManagerControllerInvoiceManager extends JControllerForm
{
function save(){
$file = JRequest::getVar( 'invoice', '', 'files', 'array' );
var_dump($file);
exit(0);
}
}
推荐答案
请确保您以提交文件的形式包含了enctype="multipart/form-data"
.这是一个常见的错误
make sure that you have included enctype="multipart/form-data"
in the form that the file is being submitting. This is a common mistake
/// Get the file data array from the request.
$file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
/// Make the file name safe.
jimport('joomla.filesystem.file');
$file['name'] = JFile::makeSafe($file['name']);
/// Move the uploaded file into a permanent location.
if (isset( $file['name'] )) {
/// Make sure that the full file path is safe.
$filepath = JPath::clean( $somepath.'/'.strtolower( $file['name'] ) );
/// Move the uploaded file.
JFile::upload( $file['tmp_name'], $filepath );}
这篇关于将文件上传器添加到Joomla管理组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!