Add File Uploader to Joomla Admin Component(将文件上传器添加到 Joomla 管理组件)
问题描述
我根据 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.
在administratorcomponentscom_invoicemanagermodelsformsinvoicemanager.xml 中我已经定义了
In administratorcomponentscom_invoicemanagermodelsformsinvoicemanager.xml i have defined
<field name="invoice" type="file"/>
在控制器 administratorcomponentscom_invoicemanagercontrollersinvoicemanager.php 中,我尝试检索该文件,如下所示.但它不起作用(无法检索文件)
In the controller administratorcomponentscom_invoicemanagercontrollersinvoicemanager.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 管理组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将文件上传器添加到 Joomla 管理组件


基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01