我根据 Joomla 指南制作了 Joomla 管理组件 -http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component
因为我需要有文件上传器,让用户上传单个文件。
在administrator\components\com_invoicemanager\models\forms\invoicemanager.xml中我定义了
<field name="invoice" type="file"/>
在控制器administrator\components\com_invoicemanager\controllers\invoicemanager.php中,我尝试检索该文件,如下所示。但它不起作用(无法检索文件)
我哪里做错了?
我如何获取文件并将其保存在磁盘上?
class InvoiceManagerControllerInvoiceManager extends JControllerForm
{
function save(){
$file = JRequest::getVar( 'invoice', '', 'files', 'array' );
var_dump($file);
exit(0);
}
}
确保您已包含enctype="multipart/form-data"
以文件正在提交的形式。这是一个常见的错误
/// 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 );}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)