我对此有点纠结。我有一小段代码,它设法获得我的文件的文件名:
class AControllerA extends JControllerForm
{
function save()
{
//Upload file
jimport('joomla.filesystem.file');
$jinput = JFactory::getApplication()->input;
$store_form = $jinput->get('jform', null, 'array');
$file = $store_form['img_url'];
echo $file;
}
}*文件字段的名称为jformimg_url;
然而,我似乎无法获得该文件的'tmp_name‘。有人知道我错过了什么吗?对于jinput works...jrequest是如何轻松工作的,我有点困惑。谢谢!
模型/表单/a.xml
<form enctype="multipart/form-data">
<fieldset>
<field
name="img_url"
type="file"
label=""
description=""
size="40"
class="inputbox"
default=""
/>
</fieldset>
</form>发布于 2013-03-28 15:56:10
这样如何:
$files = $input->files->get('jform', null);
$filename = $files['img_url']['tmp_name'];
echo $filename;查看Retrieving file data using JInput的文档
发布于 2013-03-28 15:58:04
假设您使用的是JForm和文件输入类型,那么您可以使用以下命令访问该文件:
$files = $jinput->files->get('jform');
$file = $files['img_url']['tmp_name']还要确保您的表单设置了enctype="multipart/form-data",否则它将无法工作。
发布于 2013-12-04 14:23:38
在你的模型中,你应该有这样的东西
public function getForm($data = array(), $loadData = false)
{
/**
* Get the Form
*/
$form = $this->loadForm('com_mycomponent.mycomponent', 'mycomponent',
array('control' => false, 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}请注意,$loaddata和'control‘设置为false,当'control’设置为false时,您可以根据xml中指定的名称获取文件参数,即输出形式如下:
<input name="name in xml file" type="file" />If‘=>’控制'jform‘
<input name="jform[name in xml file]" type="file" />$loaddata= false表示您不需要从数据库获取任何数据到表单。
在你的view.html.php中,你应该有这样的东西
public function display($tpl = null)
{
$this->formData = $this->get('Form');
$this->addToolbar();
parent::display($tpl);
}假设我在"mycomponent“控制器的"upload”方法中接收到请求的文件,那么它应该有如下内容:
class MycomponentControllerMycomponent extends JControllerAdmin
{
public function upload()
{
//Retrieve file details from uploaded file, sent from upload form
$file = JFactory::getApplication()->input->files->get('name in xml
**$tmp_name** = $file['tmp_name'];
}
}$tmp_name是您需要的名称
https://stackoverflow.com/questions/15675149
复制相似问题