1. 程式人生 > >織夢獲取自定義欄位附件型別檔案的格式型別檔案大小上傳日期

織夢獲取自定義欄位附件型別檔案的格式型別檔案大小上傳日期

內容頁顯示效果

實現步驟

1、\templets\system\channel_addon.htm 裡面要清空,只留~link~   (注意:前後不能留有一個空格)

2、/include/extend.func.php  最下面加入方法

function GetFileInfos($file, $type='size')
{
    global $cfg_basedir;
    $filepath = $cfg_basedir.$file;
    $size = filesize($filepath);
    $fileinfos = pathinfo($filepath);
    $units = array(' B', ' KB', ' MB', ' GB', ' TB');
    for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
    if($type=='size') return round($size, 2).$units[$i];
    if($type=='type') return $fileinfos['extension'];
    if($type=='name') return $fileinfos['filename'];
    if($type=='time') return MyDate("Y-m-d H:i:s", filemtime($filepath));
}

3、內容模板 呼叫標籤

名稱:{dede:field.download function=GetFileInfos(@me,name)/}
型別:{dede:field.download function=GetFileInfos(@me,type)/}
大小:{dede:field.download function=GetFileInfos(@me,size)/}
時間:{dede:field.download function=GetFileInfos(@me,time)/}