-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyfunctions.php
97 lines (78 loc) · 2.72 KB
/
myfunctions.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
include_once 'Include/header.php';
function generateRandomString($length = 32) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
if (isset($_POST['createNewFile']))
{
session_start();
createNewFile();
}
function createNewFile()
{
$token = $_POST['token_new_file'];
if (!$token || $token !== $_SESSION['token_new_file']) {
// return 405 http status code
header($_SERVER['SERVER_PROTOCOL'] . ' 405 Method Not Allowed');
exit;
} else {
if (!empty($_POST["new_file_name"])) {
$new_file_name = test_input($_POST["new_file_name"]);
// check for security validation later
$sub_dir = $_POST["sub_directory"];
$username = $_SESSION['Username'];
if (!empty($sub_dir)) {
fopen($username.'/'. $sub_dir.'/'. $new_file_name, "w");
header("location: upload.php?p=".$sub_dir);
}else {
fopen($username.'/'. $new_file_name, "w");
header("location: upload.php");
}
exit();
}else
echo "<a href=$upload_page_url class='btn btn-primary'>" . "Back" . "</a>";
}
}
if (isset($_POST['createNewFolder']))
{
session_start();
createNewFolder();
}
function createNewFolder()
{
// $token = filter_input(INPUT_POST, 'token_upload', FILTER_SANITIZE_STRING);
$token = $_POST['token_new_folder'];
if (!$token || $token !== $_SESSION['token_new_folder']) {
// return 405 http status code
header($_SERVER['SERVER_PROTOCOL'] . ' 405 Method Not Allowed');
exit;
} else {
if (!empty($_POST["new_folder_name"])) {
$new_folder_name = test_input($_POST["new_folder_name"]);
$sub_dir = $_POST["sub_directory"];
$username = $_SESSION['Username'];
if (!empty($sub_dir)) {
mkdir($username.'/'.$sub_dir.'/'.$new_folder_name ,0700,true); //permissions are ignored on Windows.
header("location: upload.php?p=".$sub_dir);
}else {
mkdir($username.'/'.$new_folder_name ,0700,true); //permissions are ignored on Windows.
header("location: upload.php");
}
exit();
}else
echo "<a href=$upload_page_url class='btn btn-primary'>" . "Back" . "</a>";
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}