-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.php
More file actions
64 lines (49 loc) · 1.47 KB
/
delete.php
File metadata and controls
64 lines (49 loc) · 1.47 KB
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
<?php
session_start();
if(isset($_GET["file_id"]) && isset($_GET["kind"]) && isset($_SESSION["id"])){
$user_id = $_SESSION["id"];
$file_id = $_GET["file_id"]; //file id
if(isset($_GET["csrf_token"]) && isset($_SESSION["csrf_token"])){
if($_GET["csrf_token"] !== $_SESSION["csrf_token"]){
echo("403 Error");
http_response_code(403);
exit();
}
}else{
echo("403 Error");
http_response_code(403);
exit();
}
$all_content = "";
$file_delete = false;
if($_GET["kind"] == "doc"){
$search_folder = "search";
}elseif($_GET["kind"] == "question"){
$search_folder = "question";
}elseif($_GET["kind"] == "discussion"){
$search_folder = "discussion";
}
//検索結果を更新
//削除するファイルの情報を消す
$lines = file("./".$search_folder."/".$user_id.".csv");
foreach($lines as $line){
$data = explode('($split)',$line);
if(count($data) == 3){
if($data[1] === $file_id){
//ファイル削除
unlink("./data/".$file_id.".md");
$file_delete = true;
}else{
$all_content .= $line;
}
}
}
$filename = './'.$search_folder.'/'.$user_id.'.csv';
$fp = fopen($filename, 'w');
fputs($fp, $all_content);
fclose($fp);
if($file_delete == false){
http_response_code(403);
}
}
?>