gpt4 book ai didi

joomla - joomla模块中的文件上传

转载 作者:行者123 更新时间:2023-12-02 08:11:08 25 4
gpt4 key购买 nike

我已经搜索了很长一段时间,但找不到符合我需求的解决方案。我正在为 Joomla 2.5 开发一个模块。我需要允许用户在模块配置中从后端上传图像/任何文件类型的功能。

问题:如何在 joomla 模块中添加文件上传字段。

谢谢!

最佳答案

只是 joomla 文档中的一个示例:

<?php

//Retrieve file details from uploaded file, sent from upload form
$file = JRequest::getVar('file_upload', 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 . DS . "uploads" . DS . $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) ) {
header("Location: http://".$_SERVER["HTTP_HOST"]."/administrator"); Redirect to a page of your choice
} else {
echo "error !"; //Redirect and throw an error message
}
} else {
echo "Wrong extension !"; //Redirect and notify user file is not right extension
}

?>

有关更多详细信息和完整示例:http://docs.joomla.org/How_to_use_the_filesystem_package

关于joomla - joomla模块中的文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10869157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com