2 DB 14 2 download num int not
2. DB 테이블 설계 및 생성 [표 14 -2] 자료실 데이터베이스 테이블(테이블명: download) 필드명 형식 추가 사항 설명 num int not null, auto_increment, primary key 일련번호 id char(15) not null 아이디 name char(10) not null 이름 nick char(10) not null 닉네임 subject char(100) not null 제목 content text not null 글 내용 regist_day char(20) 작성일 hit int 조회수 file_name_0 char(40) 첨부파일 1의 파일명 file_name_1 char(40) 첨부파일 2의 파일명
download 데이터베이스 테이블 생성 create table download ( num int not null auto_increment, id char(15) not null, name char(10) not null, nick char(10) not null, subject char(100) not null, content text not null, regist_day char(20), hit int, file_name_0 char(40), file_name_1 char(40), file_name_2 char(40), file_name_3 char(40), file_name_4 char(40), file_copied_0 char(30), file_copied_1 char(30), file_copied_2 char(30), file_copied_3 char(30), file_copied_4 char(30), file_type_0 char(30), download. sql file_type_1 char(30), file_type_2 char(30), file_type_3 char(30), file_type_4 char(30), primary key(num) );
예제 14 -1 자료실의 글 내용 보기 페이지 001 <? 002 session_start(); 003 include ". . /lib/dbconn. php"; 004 005 $sql="select * from $table where num=$num"; 006 $result=mysql_query($sql, $connect); 007 $row=mysql_fetch_array($result); 008 009 $item_num=$row[num]; 010 $item_id=$row[id]; 011 $item_name=$row[name]; 012 $item_nick=$row[nick]; 013 $item_hit=$row[hit]; 014 015 $file_name[0]=$row[file_name_0]; 016 $file_name[1]=$row[file_name_1]; 017 $file_name[2]=$row[file_name_2]; 018 view. php
예제 14 -1 자료실의 글 내용 보기 페이지 019 $file_type[0]=$row[file_type_0]; 020 $file_type[1]=$row[file_type_1]; 021 $file_type[2]=$row[file_type_2]; 023 $file_copied[0=$row[file_copied_0]; 024 $file_copied[1=$row[file_copied_1]; 025 $file_copied[2=$row[file_copied_2]; 026 027 $item_date=$row[regist_day]; 028 $item_subject=str_replace(" ", " ", $row[subject]); 029 $item_content=str_replace(" ", " ", $row[content]); 030 $item_content=str_replace("n", " ", $item_content); 031 $new_hit = $item_hit + 1; 032 033 $sql="update $table set hit=$new_hit where num=$num"; 034 mysql_query($sql, $connect); 035 ? > 036 <!DOCTYPE HTML PUBLIC "-//W 3 C//DTD HTML 4. 01 Transitional//EN“ "http: //www. w 3. org/TR/html 4/loose. dtd"> view. php
예제 14 -1 자료실의 글 내용 보기 페이지 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 view. php <html> <head> <meta charset="euc-kr"> <link href=". . /css/common. css" rel="stylesheet" type="text/css" media="all"> <link href=". . /css/board 3. css" rel="stylesheet" type="text/css" media="all"> <script> function del(href) { if(confirm("한번 삭제한 자료는 복구할 방법이 없습니다. nn 정말 삭제하시겠습니까? ")) { document. location. href=href; } } </script> </head>
예제 14 -1 자료실의 글 내용 보기 페이지 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 <body> <div id="wrap"> <div id="header"> <? include ". . /lib/top_login 2. php"; ? > </div> <!- - end of header - -> <div id="menu"> <? include ". . /lib/top_menu 2. php"; ? > </div> <!- - end of menu - -> <div id="content"> <div id="col 1"> <div id="left_menu"> <? include ". . /lib/left_menu. php"; ? > </div> <!- - end of col 1 - -> view. php
예제 14 -1 자료실의 글 내용 보기 페이지 071 072 073 074 075 076 077 view. php <div id="col 2"> <div id="title"> <img src=". . /img/title_download. gif"> </div> <div id="view_comment"> </div> <div id="view_title"> <div id="view_title 1"><? = $item_subject ? ></div> <div id="view_title 2"> <? =$item_nick ? >|조회 : <? =$item_hit ? >|<? =$item_date ? > </div> 078 </div> 079 080 <div id="view_content"> 081 <? 082 for($i=0; $i<3; $i++) 083 { 084 if($userid && $file_copied[$i]) 085 { 086 $show_name=$file_name[$i]; // 화면에 표시되는 파일명 087 $real_name=$file_copied[$i]; // [data] 폴더에 저장된 파일명
예제 14 -1 자료실의 글 내용 보기 페이지 088 089 090 091 092 093 view. php $real_type=$file_type[$i]; $file_path=". /data/". $real_name; $file_size=filesize($file_path); echo ("▷ 첨부파일 : $show_name ($file_size Byte) <a href='download. php? table= $table&num=$num&real_name=$real_name&show_name= $show_name&file_type=$real_type'>[저장]</a> “ ); 094 } 095 } 096 ? > 097 098 <? = $item_content ? > 099 </div> 100
예제 14 -1 자료실의 글 내용 보기 페이지 101 <div id="view_button"> 102 <a href="list. php? table=<? =$table? >&page=<? =$page? >"> <img src=". . /img/list. png"></a> 103 <? 104 if($userid && $userid==$item_id) 105 { 106 ? > 107 <a href="write_form. php? table=<? =$table? >&mode=modify& num=<? =$num? >&page=<? =$page? >"><img src=". . /img/modify. png"></a> 108 <a href="javascript: del('delete. php? table=<? =$table? >&num=<? =$num? >')"> <img src=". . /img/delete. png"></a> 109 <? 110 } 111 ? > view. php
예제 14 -1 자료실의 글 내용 보기 페이지 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 view. php <? if($userid) { ? > <a href="write_form. php? table=<? =$table? >"><img src=". . /img/write. png"></a> <? } ? > </div> <div class="clear"></div> <!- - end of col 2 - -> </div> <!- - end of content - -> </div> <!- - end of wrap - -> </body> </html>
예제 14 -2 첨부파일 다운로드 01 <? session_start(); ? > 02 <? 03 if(!$userid) 04 { 05 echo(" 06 <script> 07 window. alert('로그인 후 이용해 주세요. ') 08 history. go(-1) 09 </script> 10 "); 11 exit; 12 } 13 $file_path = ". /data/". $real_name; 14 download. php
예제 14 -2 첨부파일 다운로드 15 16 17 18 19 20 21 22 23 24 25 26 27 download. php if(file_exists($file_path)) { $fp=fopen($file_path, "rb"); if($file_type) { Header("Content-type: application/x-msdownload"); Header("Content-Length: ". filesize($file_path)); Header("Content-Disposition: attachment; filename=$show_name"); Header("Content-Transfer-Encoding: binary"); Header("Content-Description: File Transfer"); Header("Expires: 0"); }
예제 14 -2 첨부파일 다운로드 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 download. php else { if(eregi("(MSIE 5. 0|MSIE 5. 1|MSIE 5. 5|MSIE 6. 0)", $HTTP_USER_AGENT)) { Header("Content-type: application/octet-stream"); Header("Content-Length: ". filesize($file_path)); Header("Content-Disposition: attachment; filename=$show_name"); Header("Content-Transfer-Encoding: binary"); Header("Expires: 0"); } else { Header("Content-type: file/unknown"); Header("Content-Length: ". filesize($file_path)); Header("Content-Disposition: attachment; filename=$show_name"); Header("Content-Description: PHP 3 Generated Data"); Header("Expires: 0"); } }
예제 14 -2 첨부파일 다운로드 47 if(!fpassthru($fp)) 48 fclose($fp); 49 } 50 ? > download. php
- Slides: 28