dz默认的板块路径是data/attachment/forum/202210/10/xxxxx.xx,有位站长希望改成data/attachment/forum/{FID}/202210/xxxx.xx这样的路径。也就是以板块id为目录来存放文件,话不多数,直接上代码;
打开文件:source/class/discuz/discuz_upload.php里面有一个get_target_dir方法,这个方法就是用来返回存放路径的,我们修改如下:
function get_target_dir($type, $extid = '', $check_exists = true) {
$subdir = $subdir1 = $subdir2 = '';
if($type == 'album' || $type == 'forum' || $type == 'portal' || $type == 'category' || $type == 'profile') {
$subdir1 = date('Ym');
$subdir2 = date('d');
$subdir = $subdir1.'/'.$subdir2.'/';
} elseif($type == 'group' || $type == 'common') {
$subdir = $subdir1 = substr(md5($extid), 0, 2).'/';
}
$check_exists && discuz_upload::check_dir_exists($type, $subdir1, $subdir2);
//return $subdir;
/**新增部分**/
$res = $_SERVER['HTTP_REFERER']; // 根据referer信息来获取fid
$urlinfo = parse_url($res);
$query_str = $urlinfo['query'];
$query_arr =$this->getUrlQuery($query_str);
if(isset($query_arr['fid'])){
$fid = $query_arr['fid'];
discuz_upload::check_dir_exists($type, $fid, $subdir1);
}
return $fid.'/'.$subdir1.'/';
}
里面用到了getUrlQuery方法,定义如下:
function getUrlQuery($array_query) {
$arr = explode('&', $array_query);
$tmp = array();
foreach ($arr as $k) {
$temp_arr = explode('=', $k);
if (count($temp_arr) == 2) {
$k = $temp_arr[0];
$v = $temp_arr[1];
$tem[$k] = $v;
}
}
return $tem;
}
这里面主要参考了网友的文章,链接地址:
https://blog.csdn.net/majingchang/article/details/79956798
有关PHP系统、Discuz或网站等各种问题,可以联系QQ1069971363寻求付费支持
|