我在创建自定义字段的上传机制时遇到了困难:libraries/joomla/filesystem/file.php。该表单在视图中设置了正确的enctype,它只是不上传。下面是我的组件/模型/场/ uploadfield.php代码:Joomla自定义组件上传表单
protected function getInput()
{
//Retrieve file details from uploaded file, sent from upload form
$file = JFactory::getApplication()->input->get($this->name, null, 'files', 'array');
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name']);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = JPATH_COMPONENT . DIRECTORY_SEPARATOR . $filename;
//First check if the file has the right extension, we need jpg only
if (strtolower(JFile::getExt($filename)) == 'jpg') {
if (JFile::upload($src, $dest)) {
//Redirect to a page of your choice
} else {
//Redirect and throw an error message
}
} else {
//Redirect and notify user file is not right extension
}
return '<input type="file" name="' . $this->name . '" id="' . $this->id . '"' . ' />';
}
上午我甚至会对此具有处于getInput()函数上传机制的正确方法?它应该在模型中吗?我真的坚持如何使这项工作,一直试图遵循:http://docs.joomla.org/How_to_use_the_filesystem_package但它忽略了上传代码应该去哪里?
非常感谢
你好,非常感谢您的答复 - 我已经试过这一点,它不似乎工作 - 该字段出现在视图上,我可以选择一个文件,但似乎并没有在任何地方上传?我使用Joomla 3.0,所以JRequest :: getVar现在已经被替换为:JFactory :: getApplication() - > input-> get()。 – mousebat
啊,我不知道你在使用Joomla 3.0。我会尝试进行必要的更改 – Lodder
@ user1717113 - 我已更新我的答案 – Lodder