게시판에 올린 파일중에 첫번째 파일 url 출력 문의입니다.

게시판에 올린 파일중에 첫번째 파일 url 출력 문의입니다.

QA

게시판에 올린 파일중에 첫번째 파일 url 출력 문의입니다.

본문

안녕하세요

게시물에 파일을 여러개 올렸을 때, 뷰페이지에서

첫번째 이미지의 파일 이름(g5_board_file 테이블의 bf_file)을 출력하고 싶습니다.

 

문제를 해결못해 도움을 요청드립니다 ㅠㅠ

 

이 질문에 댓글 쓰기 :

답변 2

그누보드에 이런함수가 있습니다.

 

// 게시글에 첨부된 파일을 얻는다. (배열로 반환)
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'];
        $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'] = $row['bf_content'];
        $file[$no]['content'] = get_text($row['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;
}

 

 

//사용방법

$file_arr = get_file(게시판명, 게시물번호);​

 

//이미지 첫번째 파일 출력코자 할때...

for($i=0; $i<count($file_arr); $i++){
 if($file_arr[$i]['type'] == 2){
  echo $file_arr[$i]['path']."/".$file[$i]['file'];
  break;
 }
}

//그냥 첫번째파일 출력일때..

echo $file_arr[0]['path']."/".$file[0]['file'];

<?php
//사용방법

$file_arr = get_file($bo_table, $wr_id);​
 
//그냥 첫번째파일 출력일때..

echo $file_arr[0]['path']."/".$file[0]['file'];
?>

를 뷰페이지에 삽입하였더니

Parse error: syntax error, unexpected T_ECHO in /home/skin/board/product/view.skin.php on line 406

오류가 발생하였습니다.
406라인은 echo $file_arr[0]['path']."/".$file[0]['file']; 구문입니다.

초보라서 적어주신 소스를 다 넣어 보기도 하고 하다가 댓글에 적은 소스만 넣으면 출력이 될 줄 알았는데 안되네요 힌트를 좀 더 주실 수 없을까요?

소스상의 문제는 없구요.

$file_arr = get_file($bo_table, $wr_id);​ 
echo $file_arr[0]['path']."/".$file[0]['file'];

 

 

$wr_id

$bo_table

의 값이 제대로 들어가있는지 확인하셔야 할듯...

보통

$view['wr_id'] 요런변수에 값이 담겨있을듯 싶은데...

$file_arr = get_file($bo_table, $view['wr_id']);​ 


사실 게시판의 view부분이라면...

echo $view['file'][0]['path']."/".$view['file'][0]['file'];

이렇게만 쓰셔도 됩니다.

 

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

회원로그인

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