2009년 11월 24일 화요일

내 홈페이지에 사용한 메모장 소스

homepage 
위에 보시면 Note List 라고 보이실 꺼에요
간단한 메모장을 이용하여 메인에 넣은 모습입니다. 혹시나 필요하신 분은 아레 소스를 참고 하시거나 사이트를 참고 하시길 바랍니다. ( 본소스는 원소스에 대한 기본틀을 위지 하였습니다 )

파일 구성은 아레와 같습니다.


1. 글작성 : memo.php
2. 글출력 : index.php ( 최근 내용만 ) 대략 6-7개정도 (글 내용에 따라 달라 집니다. )
               메인 구성이 틀고정으로 하였기 때문에 기 작성한 메모에 대해서는 짤리는 모습을 보입니다.
3. hader.php : index.php 해더 부분을 따로 때서 만든 파일로써 타이틀과 메뉴가 구성 되여 있습니다.
4. footer.php : index.php 하단 제작자 및 템플릿 제작자에 대한 링크가 걸려 있는 파일 입니다.
5. 메모장 모둔 내용 출력 : memo_list.php ( 메모장 글작성 링크 및 기 작성된 메모에 대해 모둔 내용을 출력)
6. basic-css.css : hader.php 및 footer.php, index.php에 적용한 스타일
* 저의 경우 root계정 아레에 data라는 폴더를 만들고 memo.txt 파일의 권한은 777 으로 하였습니다.

파일명 : hader.php
홈페이지 타이틀과 메뉴로 구성 되여 있습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="basic-css.css" />
<title>Test Web pasge</title>
</head>
<body>
<div id="container">
<div id="header">

<div class="headerhead">Mizrino Homepage</div>
<div id="links">
<div>
<span class="link"><a href="./index.php">Home</a></span>
<span class="link"><a href="./memo_list.php">Memo FUll List</a></span>

</div>
</div>
</div>

파일명 : memo_list.php
기 작성된 메모(방명록)에 대한 내용을 출력 하기 위해 만든 문서 입니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Memmo</title>
<style type="text/css">
<!--
.메모장입력 {
    text-align: right;
}
-->
</style>
</head>
<body>
<? include('hader.php'); ?>
<?
// 사용할 파일 정의
$savefile = "./data/memo.txt";

// 넘어온 변수를 체크한다. 내용이 비어있지 않으면 파일을 열어 기록한다.
if($_POST[contents]){
    // 파일을 쓰기전용으로 열고  포인터를 제일 뒤에 놓도록 한다.
    $fp = fopen($savefile, "a");

    // 내용을 쓴다. 제일위에 개행문자인 \n을 적어서 한줄을 띄운다.
    fwrite($fp, $_POST[contents]."\n");

    fclose($fp);
}
?>
<form method="post" name="iForm" class="메모장입력">
  <a href="./memo.php" target="_blank">메모장 입력</a>
</form>

<?
// 출력할 내용으로 사용할 배열변수를 정의한다.
$display = array();

// 파일이 존재하면 다음을 수행한다. file_exists 함수는 파일이 있는지 없는지 조사하는 함수이다.
if(file_exists($savefile)){
// 파일을 읽기 전용으로 연다.
$fp = fopen($savefile, "r");

// 파일을 끝까지 읽는다.
while(!feof($fp)) {
    // 파일의 내용을 한줄씩 1000자를 읽어와 배열변수에 추가한다.
    $display[] = fgets($fp, 1000);
}
//파일을 닫는다.
fclose($fp);
}
?>

<!-- 방명록 내용 -->
<table style="width:100%;border:1px #CCCCCC solid;">
    <tr>
        <td align="center" valign="middle" style="width:100%;padding:5px 5px 5px 5px;font-zise:15px;font-weight:bold;">Note List</td>
    </tr>
<?
// 내용이 한줄이라도 있으면 출력한다.
if(count($display) > 0){

    // 배열의 마지막 key 값을 구한다. 배열의 key 는 0부터 시작하므로 마지막 key 는 갯수에서 1을 뺴면 된다.
    $last_key = count($display) - 1;

    // 최근 내용부터 출력해야하므로 배열의 마지막 부터 처음까지 반복한다.
    for($i = $last_key;$i >= 0;$i--){
        // 방명록의 내용이 있으면 출력한다.
        if($display[$i]){
    ?>
    <tr>
        <td align="center" valign="middle" style="width:100%;height:1px;background-color:#CCCCCC;"></td>
    </tr>
    <tr>
        <td align="left" valign="middle" style="width:100%;padding:5px 5px 5px 5px;"><?=$display[$i]?></td>
    </tr>
    <?
        }
    }
}
?>
</table>
<? include('footer.php'); ?>
</body>
</html>

파일명 : footer.php
index.php, memo_list.php에 사용한 홈페이지 제작자 및 템플릿 제작자 표시부분

<div id="footer">Created by <a href="mailto:mizrino@gmail.com">Mizrino</a> 2009-11-21 12:32 and Copyright &copy; Pyser Webdesigns</div>
</body>
</html>

파일명 : basic-css.css
타이틀 및 메뉴/홈페이지 제작자의 스타일

body {background:#e8e8e8; font-family:Arial, Helvetica, sans-serif; font-size:12px; background:url('images/bg.gif');}
#container {margin: 0 auto; width: 776px;}
#header {background:url(header.png); width: 776px; height: 138px; z-index:-1;}
#links {font-family: arial; width:734px; margin: 0 auto; color:white; font-size: 1.7em; float:left; padding-top:55px;}
.link {padding-left:28px;}
#content {background:#f1eded;  width:756px; margin-left:55px; margin-top:0px; overflow:hidden; margin: 0 auto;}
.link a {text-decoration:none; color:#000;}
.link a:hover {color:#999;}
#main {}
#main .headerer {width:669px; height:28px; margin-top:30px; margin-bottom: 20px; float:left; margin-left:45px;}
#main .body    {background:#e8e6e6;}
#footer    {background:url(images/footer.png); width:737px; height:10px; margin: 0 auto; clear:both;}
.headertitle {font-family:'Arial Rounded MT bold'; color:#CCC; font-size:2em; padding:2px; background:#3e4142;}
.bodycontent {width: 600px; height: 450px; margin-left:44px; margin-top:-20px; background:#ececec; float:left; padding-top:20px; padding-left: 20px; padding-right:50px; clear:both; padding-bottom: 20px;}
.headerhead {float:right; font-size: 2em; color:#CCCCCC; font-weight:bold; margin-right: 500px; margin-top:20px; z-index: 1;}
#images    {width:700px;}

 

파일명 : memo.php
메모장(방명록) 글 작성폼이 있는 문서 입니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Memmo</title>
<style type="text/css">
<!--
.메모장입력 {
    text-align: right;
}
-->
</style>
</head>
<body>
<? include('hader.php'); ?>
<?
// 사용할 파일 정의
$savefile = "./data/memo.txt";

// 넘어온 변수를 체크한다. 내용이 비어있지 않으면 파일을 열어 기록한다.
if($_POST[contents]){
    // 파일을 쓰기전용으로 열고  포인터를 제일 뒤에 놓도록 한다.
    $fp = fopen($savefile, "a");

    // 내용을 쓴다. 제일위에 개행문자인 \n을 적어서 한줄을 띄운다.
    fwrite($fp, $_POST[contents]."\n");

    fclose($fp);
}
?>
<form method="post" name="iForm" class="메모장입력">
  <a href="./memo.php" target="_blank">메모장 입력</a>
</form>

<?
// 출력할 내용으로 사용할 배열변수를 정의한다.
$display = array();

// 파일이 존재하면 다음을 수행한다. file_exists 함수는 파일이 있는지 없는지 조사하는 함수이다.
if(file_exists($savefile)){
// 파일을 읽기 전용으로 연다.
$fp = fopen($savefile, "r");

// 파일을 끝까지 읽는다.
while(!feof($fp)) {
    // 파일의 내용을 한줄씩 1000자를 읽어와 배열변수에 추가한다.
    $display[] = fgets($fp, 1000);
}
//파일을 닫는다.
fclose($fp);
}
?>

<!-- 방명록 내용 -->
<table style="width:100%;border:1px #CCCCCC solid;">
    <tr>
        <td align="center" valign="middle" style="width:100%;padding:5px 5px 5px 5px;font-zise:15px;font-weight:bold;">Note List</td>
    </tr>
<?
// 내용이 한줄이라도 있으면 출력한다.
if(count($display) > 0){

    // 배열의 마지막 key 값을 구한다. 배열의 key 는 0부터 시작하므로 마지막 key 는 갯수에서 1을 뺴면 된다.
    $last_key = count($display) - 1;

    // 최근 내용부터 출력해야하므로 배열의 마지막 부터 처음까지 반복한다.
    for($i = $last_key;$i >= 0;$i--){
        // 방명록의 내용이 있으면 출력한다.
        if($display[$i]){
    ?>
    <tr>
        <td align="center" valign="middle" style="width:100%;height:1px;background-color:#CCCCCC;"></td>
    </tr>
    <tr>
        <td align="left" valign="middle" style="width:100%;padding:5px 5px 5px 5px;"><?=$display[$i]?></td>
    </tr>
    <?
        }
    }
}
?>
</table>
<? include('footer.php'); ?>
</body>
</html>

파일명 : Index.php
memo.php에서 작성한 메모(TEXT) 파일(./data/memo.txt)를 읽어 들여 메인에 출력하는 소스 입니다.

<? include('hader.php'); ?>
<div id="content">
<div id="main">
<div class="headerer">
<div class="headertitle">Home</div></div>

<div class="bodycontent">
<p>
<?
// 사용할 파일 정의
$savefile = "./data/memo.txt";

// 넘어온 변수를 체크한다. 내용이 비어있지 않으면 파일을 열어 기록한다.
if($_POST[contents]){
    // 파일을 쓰기전용으로 열고  포인터를 제일 뒤에 놓도록 한다.
    $fp = fopen($savefile, "a");

    // 내용을 쓴다. 제일위에 개행문자인 \n을 적어서 한줄을 띄운다.
    fwrite($fp, $_POST[contents]."\n");

    fclose($fp);
}
?>
<form name="iForm" method="post">
</form>

<?
// 출력할 내용으로 사용할 배열변수를 정의한다.
$display = array();

// 파일이 존재하면 다음을 수행한다. file_exists 함수는 파일이 있는지 없는지 조사하는 함수이다.
if(file_exists($savefile)){
// 파일을 읽기 전용으로 연다.
$fp = fopen($savefile, "r");

// 파일을 끝까지 읽는다.
while(!feof($fp)) {
    // 파일의 내용을 한줄씩 1000자를 읽어와 배열변수에 추가한다.
    $display[] = fgets($fp, 1000);
}
//파일을 닫는다.
fclose($fp);
}
?>

<!-- 방명록 내용 -->
<table style="width:620px;border:1px #CCCCCC solid;">
    <tr>
        <td align="left" valign="middle" style="width:500px;padding:5px 5px 5px 5px;font-zise:15px;font-weight:bold;">Note List</td>
    </tr>
<?
// 내용이 한줄이라도 있으면 출력한다.
if(count($display) > 0){

    // 배열의 마지막 key 값을 구한다. 배열의 key 는 0부터 시작하므로 마지막 key 는 갯수에서 1을 뺴면 된다.
    $last_key = count($display) - 1;

    // 최근 내용부터 출력해야하므로 배열의 마지막 부터 처음까지 반복한다.
    for($i = $last_key;$i >= 0;$i--){
        // 방명록의 내용이 있으면 출력한다.
        if($display[$i]){
    ?>
    <tr>
        <td align="center" valign="middle" style="width:500px;height:1px;background-color:#CCCCCC;"></td>
    </tr>
    <tr>
        <td align="left" valign="middle" style="width:500px;padding:5px 5px 5px 5px;"><?=$display[$i]?></td>
    </tr>
    <?
        }
    }
}
?>
</table>
</p>
<div id="images"></div>
</div>

</div>

</div>

</div>
<? include('footer.php'); ?>

0 개의 댓글:

댓글 쓰기