我在創建自定義字段的上傳機制時遇到了困難: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