<?php
// 💚 등록된 도서 전송
// post 전송으로 전송된 데이터는 슈퍼글로벌 $_POST 전역변수로 받음
// $_POST 는 연관배열인 $_POST['keyname']
// var_dump($_POST);
$id = $_POST['id'];
$desc = $_POST['description'];
file_put_contents('../data/'.$id, $desc);
// 리다이렉션
header('Location:../index.php');
?>
process > edit_process.php
<?php
// 파일 이름 변경하기 rename(파일이름, 변경할이름)
rename('../data/'.$_POST['old_id'], '../data/'.$_POST['id']);
// 파일 내용 변경하기 file_put_contents(파일이름, 내용)
file_put_contents('../data/'.$_POST['id'], $_POST['description']);
header('Location:../index.php');
?>
process > delete_process.php
<?php
// 💚 파일 삭제하기 unlink(파일경로)
unlink('../data/'.$_POST['id']);
header('Location:../index.php');
?>
include > header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>횽 Blog</title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<?php
// scandir() 폴더에 있는 항목을 연관배열로 반환
// 0 => "." , 1 => ".."
// 배열길이 count(배열변수)
// array(6) { [0]=> string(1) "." [1]=> string(2) ".."
// [2]=> string(35) "멈추고 호흡하고 선택하라"
// [3]=> string(54) "아티스트 웨이, 마음의 소리를 듣는 시간"
// [4]=> string(56) "일 잘하는 사람의 시간은 다르게 흘러간다"
// [5]=> string(38) "일하면서 성장하고 있습니다" }
// $lists = scandir('data/');
// var_dump($lists);
// 💚 책 리스트를 html출력
function creatList() {
$lists = scandir('data/');
for($i=0; $i<count($lists); $i++) {
// 변수
$title = $lists[$i];
if($lists[$i] != "." && $lists[$i] !="..") {
// 쿼리스트링 ) ? 뒤에 데이터 전달
echo "<li><a href='index.php?id=${title}'>${title}</a></li>";
}
}
}
// 💚 책 제목을 html출력
function printTitle() {
// $_GET['id'] 이 존재하는지 ?
if(isset($_GET['id'])) { // 존재하면 값 넣어줌(출력)
echo $_GET['id'];
} else { // 존재하지 않을시
echo "Blog";
}
}
// 💚 책 내용을 html출력
function printDesc() {
if(isset($_GET['id'])) {
echo file_get_contents('data/'.$_GET['id']);
} else {
echo "저희 Blog를 방문해주셔서 감사합니다.";
}
}
?>
<div id="wrap">
<header>
<h1><a href="index.php">Green Blog</a></h1>
<ul>
<li><a href="index.php">홈</a></li>
<li><a href="create.php">글쓰기</a></li>
</ul>
</header>
include > footer.php
<footer>
<p>copyright (c) all rights reserved.</p>
<h1>Green Blog</h1>
</footer>
</div>
</body>
</html>