이제 그누보드를 아무디렉토리에나 설치하고 사용해보자! > 그누3 팁자료실

그누3 팁자료실

이제 그누보드를 아무디렉토리에나 설치하고 사용해보자! 정보

일반 이제 그누보드를 아무디렉토리에나 설치하고 사용해보자!

본문

어제부터 고민하고 있는 상대주소에 대한 고민이 드디어 오늘에서야 해결되었습니다.
그누보드와 index.html파일과 같이 존재해야하는 불편함...
이제 어느 위치에서나 그누보드를 include해서 사용할 수 있습니다.
일단 만들어 놓은 라이브러리부터

function mappath()
{
    $reldir = getcwd();
    $rellens = strlen($reldir) - strlen(str_replace("/","",$reldir));
   
    $i=4;  //가장 상위폴더에서 index.html의 깊이까지의 / 갯수.  /home/ccc/www/ <---총 4개가 되겠죠!
    $mappaths ="";
    while ($i <= $rellens) {
        $path1 .= "../";
        $i++;
    }
    if ($path1 == "" ) $path1 = ".";  // 만약에  가장위에 폴더라면 한번도 실행하지 않기때문에
                                              // path1 값은 아무것도 존재안합니다. 그래서 자기 위치로 셋팅해줍니다.
    return $path1;
}


lib.inc.php 상에 이렇게 추가를 하고


if ($cfg[mysql_host] && $cfg[mysql_user] && $cfg[mysql_db]) {
    // 상대경로가 선언되지 않았다면
    if (!isset($reldir)) {
        $reldir = mapPath();
    }
    //-------------------------------------------
    // SESSION 설정
    //-------------------------------------------
    ini_set("session.cache_expire", "86400");
    session_save_path("$cfg[abs_path]/$cfg[dir_session]");
    if ($SESSION_CACHE_LIMITER) {
        @session_cache_limiter($SESSION_CACHE_LIMITER);
    } else {
        @session_cache_limiter('nocache, must-revalidate');
    }
    // 세션이 사라지지 않는 버그를 위하여
    if ($HTTP_COOKIE_VARS["ck_session"] == "") {
        setcookie("ck_session", "1", 0);
    }

    session_start() ;

실제 사용을 볼까요!
function view_file_link($file)
{
    global $cfg, $board, $reldir;

    if (!$file) return;

    $size = @getimagesize("$cfg[abs_url]/$cfg[dir_file]/$board[bo_table]/$file");
    $source_width  = $size[0];
    $source_height = $size[1];

    if ($board[bo_table_width] <= 100) {
        if ($size[0] > $cfg[large_image_size]) {
            $rate = $size[1] / $size[0];
            $size[0] = $cfg[large_image_size];
            $size[1] = (int)($size[0] * $rate);
        }
    } else {
        if ($size[0] > $board[bo_table_width]) {
            $rate = $size[1] / $size[0];
            $size[0] = $board[bo_table_width];
            $size[1] = (int)($size[0] * $rate);
        }
    }

    $width  = $size[0];
    $height = $size[1];

    if (preg_match($cfg[image_extension], $file))
        return "<img src='$reldir"."gnu/$cfg[dir_file]/$board[bo_table]/$file' width='$width' height='$height' border=0><p>";
    else if (preg_match($cfg[flash_extension], $file))
        return "<embed src='$reldir"."gnu/$cfg[dir_file]/$board[bo_table]/$file' width='$width' height='$height'></embed><p>";
    else if (preg_match($cfg[movie_extension], $file))
        return "<embed src='$reldir"."gnu/$cfg[dir_file]/$board[bo_table]/$file'></embed><p>";
}

// 현재 스크립트의 URL 을 얻는다
function get_current_url($http="http")
{
    global $HTTP_SERVER_VARS;

    $url = $http . "://" . $HTTP_SERVER_VARS["HTTP_HOST"] . dirname($HTTP_SERVER_VARS["PHP_SELF"]);
    // 뒤에 / 로 끝나면 / 를 없애준다
    return preg_replace("/(\/)$/", "", $url);
}


이런씩으로 모두다 수정을 해준다면....
그누보드를 어느 위치에서 불러와도 전혀 문제가 발생하지 않습니다.
예를 들어
/home/ccc/www/test/kkk.html <---여기서 lib.inc.php를 인쿨해서 사용해도 전혀문제 발생안합
/home/ccc/www/kkk.html  마찬가지겠죠
/home/ccc/www/test/ppp/rrr/iii.html <--여기도 마찬가지...

현재 이 방법대로 2.61소스를 전부다 수정중입니다. *^^*
추천
4
  • 복사

댓글 전체

© SIRSOFT
현재 페이지 제일 처음으로