-
Notifications
You must be signed in to change notification settings - Fork 2
/
member-docs-modify.php
80 lines (73 loc) · 2.85 KB
/
member-docs-modify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
// DB CONNECTION
require_once "dbcon.php";
// GET DOCS INFO
$docs_id = $_POST["docs_id"];
$title = $_POST["title"];
$detail = $_POST["detail"];
$price = $_POST["price"];
// CHECK FORMAT & GET DOCS FILE
$fileDir = $_FILES['pdfFile']['tmp_name'];
$fileTypeExt = explode(".",$_FILES['pdfFile']['name']);
$fileType = $fileTypeExt[1];
switch($fileType){
case 'txt':
case 'ppt':
case 'pptx':
case 'pdf':
break;
default:
echo "<script>alert(\"txt, ppt, pptx, pdf파일 외에는 입력이 불가합니다.\");";
echo "history.go(-1);</script>";
break;
}
// DELETE USER'S PRIOR DOC
// DELETE FILE FROM SERVER STORAGE
$docs_link_query = "SELECT * FROM file where s_id = {'$docs_id'}";
$result = mysqli_query($conn,$docs_link_query);
if($result){
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_assoc($result);
$docsArray = explode(".",$row['link']);
$docsMask = $docsArray[2];
array_map('unlink', glob("C:/xampp/htdocs/osef/uploadFile/*".$docsMask));
}
}
// DELETE FILE FROM DB
$delete_link_query = "DELETE FROM file WHERE s_id = {'$docs_id'}";
mysqli_query($conn,$delete_link_query);
// SAVE DOCS INTO SERVER LOCAL STORAGE
$fileDir = $_FILES['pdfFile']['tmp_name'];
$filename = $_FILES['pdfFile']['name'];
$splitFilename = explode(".",$filename);
$filename = "";
for($j=0;$j<count($splitFilename)-1;$j++){
$filename .= $splitFilename[$j];
}
$filename .= $docs_id.".".$splitFilename[count($splitFilename)-1];
$resFile = "./uploadFile/".$filename;
$docsUpdate = move_uploaded_file($fileDir, $resFile);
// UPDATE DOCS PATH
$insert_docs_query = "INSERT INTO file(s_id,link) VALUE ('$docs_id','$resFile');";
$insert_docs_result = mysqli_query($conn, $insert_docs_query);
// UPDATE QUERY
$update_product_query = "UPDATE sell_info SET title='$title',detail='$detail',price='$price' WHERE id='$docs_id'";
$update_product_result = mysqli_query($conn, $update_product_query);
// QUERY VERIFICATION
if($insert_docs_result != NULL && $update_product_result != NULL){ // UPDATE SUCCESS
echo '<script type="text/javascript">';
echo 'alert("문서 정보 수정 완료!!");';
echo 'window.location.href = "member-docs-info.php";';
echo '</script>';
}else{ // DB QUERY FAIL
echo '<script type="text/javascript">';
echo 'alert("예기치 않은 오류가 발생했습니다. 나중에 다시 시도하세요.");';
echo 'window.location.reload()";';
echo '</script>';
$fp = fopen('database_error_log.txt','w');
$db_err = mysqli_error($conn);
fwrite($fp,$db_err);
fclose($fp);
exit();
}
?>