file 정보 저장했다가 꺼낼려는데 출력이 안됩니다..

file 정보 저장했다가 꺼낼려는데 출력이 안됩니다..

QA

file 정보 저장했다가 꺼낼려는데 출력이 안됩니다..

본문

$bicycle_file = get_file("superintend", $result['wr_id']);
$bm_bicycle_image = apms_pack($bicycle_file[0]);

이런식으로 다른 게시판의 첫번째 파일 정보를 write_update.skin에서 저장하고 write딴에서 수정할때 이 파일정보를

$bicycle_image = apms_unpack($write['bm_bicycle_image']);

이런식으로 뽑아내고

<?php echo $bicycle_image['view']; ?> 

이렇게 출력을 할려는데 이미지가 안나옵니다ㅠㅠ 고수분들 도와주세요.. 참고로

<?php print_r2($bicycle_image); ?>

이런식으로 하면 view딴에서 뜨는 file 정보랑 똑같이 뜹니다

<?php print_r2($view['file'][0]); ?>

이랑 뜨는 정보는 똑같아요.. (한글자도 안틀리고 100%)

이 질문에 댓글 쓰기 :

답변 4

view딴에서

<?php print_r2($view['file'][0]); ?>

해보시면 파일 0번째 인덱스에 있는데 파일정보(src, width, height, size... 등등)들이 뜹니다. 이런것들이 배열로 저장 되어있는데

<?php echo $bicycle_image; ?>

이렇게 하면 array라고 뜰겁니다. 제가 원하는건 이미지를 출력하고 싶은데 view딴에서는 이미지를

<?php echo $view['file'][0]['view']; ?>

이렇게 하면 떠서 마찬가지로

<?php echo $bicycle_image['view']; ?>

이라고 하면 뜰 줄 알았는데 안뜨는게 문젭니다..ㅠㅠㅠ

$bicycle_image 여기에 뜨는 배열값을 확인해 보셨을까요?

 

배열값이 $view['file'][0] 이거의 값과 동일하다면 $view['file'][0] 3차 배열은 안되니까 뜨는게 정상인데요

 

배열값을 확인해 볼수 없어서 정확한 답변이 어렵네요

네 위에도 말씀 드렸다시피 $view['file'][0] 하고 $bicycle_image 토씨 하나 안틀리고 정확히 같습니다. db에는 제대로 들어간 것 같은데요..근데 $view['file'][0]['view'] 이렇게 하면 이미지가 뜨는데 $bicycle_image['view']라고 하면 이미지가 안뜨네요..ㅠㅠㅠ

여러분 찾았습니다. 토씨 하나 안틀린건 아니고



$bicycle_file = get_file("superintend", $result['wr_id']);
$bm_bicycle_image = apms_pack($bicycle_file[0]);

여기서 문제가 있어서 토씨 하나 정돈 틀렸네요ㅋㅋㅋㅋ get_file 함수가


function get_file($bo_table, $wr_id)
{
    global $g5, $qstr;
    $file['count'] = 0;
    $sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no ";
    $result = sql_query($sql);
    while ($row = sql_fetch_array($result))
    {
        $no = $row['bf_no'];
        $bf_content = $row['bf_content'] ? html_purifier($row['bf_content']) : '';
        $file[$no]['href'] = G5_BBS_URL."/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no" . $qstr;
        $file[$no]['download'] = $row['bf_download'];
        // 4.00.11 - 파일 path 추가
        $file[$no]['path'] = G5_DATA_URL.'/file/'.$bo_table;
        $file[$no]['size'] = get_filesize($row['bf_filesize']);
        $file[$no]['datetime'] = $row['bf_datetime'];
        $file[$no]['source'] = addslashes($row['bf_source']);
        $file[$no]['bf_content'] = $bf_content;
        $file[$no]['content'] = get_text($bf_content);
        //$file[$no]['view'] = view_file_link($row['bf_file'], $file[$no]['content']);
        $file[$no]['view'] = view_file_link($row['bf_file'], $row['bf_width'], $row['bf_height'], $file[$no]['content']);
        $file[$no]['file'] = $row['bf_file'];
        $file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640;
        $file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480;
        $file[$no]['image_type'] = $row['bf_type'];
        $file['count']++;
    }
    return $file;
}

이렇게 생겼는데 ['view']를 넣는 함수인 view_file_link가 문제였습니다


function view_file_link($file, $width, $height, $content='')
{
    global $config, $board;
    global $g5;
    static $ids;
    if (!$file) return;
    $ids++;
    // 파일의 폭이 게시판설정의 이미지폭 보다 크다면 게시판설정 폭으로 맞추고 비율에 따라 높이를 계산
    /*
    if ($width > $board['bo_image_width'] && $board['bo_image_width'])
    {
        $rate = $board['bo_image_width'] / $width;
        $width = $board['bo_image_width'];
        $height = (int)($height * $rate);
    }
    // 폭이 있는 경우 폭과 높이의 속성을 주고, 없으면 자동 계산되도록 코드를 만들지 않는다.
    if ($width)
        $attr = ' width="'.$width.'" height="'.$height.'" ';
    else
        $attr = '';
    */
    if (preg_match("/\.({$config['cf_image_extension']})$/i", $file)) {
        //$img = '<a href="'.G5_BBS_URL.'/view_image.php?bo_table='.$board['bo_table'].'&fn='.urlencode($file).'" target="_blank" class="view_image">';
        $img = '<img src="'.G5_DATA_URL.'/file/'.$board['bo_table'].'/'.urlencode($file).'" alt="'.$content.'">';
        //$img .= '</a>';
        return $img;
    }
}

이게 view_file_link 함수인데 이미지 src 넣는 과정에서 $board['bo_table']가 문제였습니다

저는 다른 테이블에 있는 파일을 가져오고 싶은데 src에 계속 현재 위치해 있는 테이블의 아이디가 src로 들어간 거였죠(그래서 이미지를 못 불러왔었네요..ㅠㅠㅠㅠ)

어쨌든 이 부분은 extend/user.config.php에 따로 함수 복사하고 이름 좀 바꾸고 이미지 src에 현재의 테이블 아이디가 아닌 매개변수로 들어간 테이블 아이디가 들어가도록 제 맛대로 바꿨습니다^^

궁금하실분이 있을거 같아서 user.config 코드도 올릴게요 감사합니다ㅠㅠ


// 게시글에 첨부된 파일을 얻는다. (배열로 반환)
function get_file_info($bo_table, $wr_id)
{
    global $g5, $qstr;
    $file['count'] = 0;
    $sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no ";
    $result = sql_query($sql);
    while ($row = sql_fetch_array($result))
    {
        $no = $row['bf_no'];
        $bf_content = $row['bf_content'] ? html_purifier($row['bf_content']) : '';
        $file[$no]['href'] = G5_BBS_URL."/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no" . $qstr;
        $file[$no]['download'] = $row['bf_download'];
        // 4.00.11 - 파일 path 추가
        $file[$no]['path'] = G5_DATA_URL.'/file/'.$bo_table;
        $file[$no]['size'] = get_filesize($row['bf_filesize']);
        $file[$no]['datetime'] = $row['bf_datetime'];
        $file[$no]['source'] = addslashes($row['bf_source']);
        $file[$no]['bf_content'] = $bf_content;
        $file[$no]['content'] = get_text($bf_content);
        //$file[$no]['view'] = view_file_link($row['bf_file'], $file[$no]['content']);
        $file[$no]['view'] = get_view_file_link($row['bf_file'], $row['bf_width'], $row['bf_height'], $file[$no]['content'], $bo_table);
        $file[$no]['file'] = $row['bf_file'];
        $file[$no]['image_width'] = $row['bf_width'] ? $row['bf_width'] : 640;
        $file[$no]['image_height'] = $row['bf_height'] ? $row['bf_height'] : 480;
        $file[$no]['image_type'] = $row['bf_type'];
        $file['count']++;
    }
    return $file;
}
// 파일을 보이게 하는 링크 (이미지, 플래쉬, 동영상)
function get_view_file_link($file, $width, $height, $content='', $bo_table)
{
    global $config, $board;
    global $g5;
    static $ids;
    if (!$file) return;
    $ids++;
    // 파일의 폭이 게시판설정의 이미지폭 보다 크다면 게시판설정 폭으로 맞추고 비율에 따라 높이를 계산
    /*
    if ($width > $board['bo_image_width'] && $board['bo_image_width'])
    {
        $rate = $board['bo_image_width'] / $width;
        $width = $board['bo_image_width'];
        $height = (int)($height * $rate);
    }
    // 폭이 있는 경우 폭과 높이의 속성을 주고, 없으면 자동 계산되도록 코드를 만들지 않는다.
    if ($width)
        $attr = ' width="'.$width.'" height="'.$height.'" ';
    else
        $attr = '';
    */
    if (preg_match("/\.({$config['cf_image_extension']})$/i", $file)) {
        //$img = '<a href="'.G5_BBS_URL.'/view_image.php?bo_table='.$board['bo_table'].'&fn='.urlencode($file).'" target="_blank" class="view_image">';
        $img = '<img src="'.G5_DATA_URL.'/file/'.$bo_table.'/'.urlencode($file).'" alt="'.$content.'">';
        //$img .= '</a>';
        return $img;
    }
}

view_file_link 이름을 get_view_file_link로 바꾸고 매개변수 하나 추가해서 get_file_info에 들어온 매개변수를 집어넣게 해놨습니다. 그리고 이미지 src에 $board['bo_table']이 아닌 $bo_table가 들어가게 해놨구요. 정상 작동하네요^^

답변을 작성하시기 전에 로그인 해주세요.
전체 123,665 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT