blob: f3ef5506f87db0d0d7e9fc59a81f0091611f8a50 (
plain)
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
require_once "database.php";
require_once "configuration.php";
require_once "file_type_recogniser.php";
require_once "user.php";
require_once "node.php";
session_start();
if (!isset( $_POST["filename"]) ||
(!isset($_FILES["the_file"]) && (!isset($_POST['content']) || gettype($_POST['content'])!="string"))
|| !isset($_POST['parent_directory']) || !isset($_POST['overwrite']))
{
error_log("someone tried to upload something impropperly");
http_response_code(400);
exit(1);
}
$file=$_FILES["the_file"];
$filename=$_POST["filename"];
$parent_directory=$_POST["parent_directory"];
$user=$_SESSION['user_object'];
$homedir=$user->home_directory;
$overwrite=$_POST['overwrite'];
$dir = get_directory($parent_directory, $user);
if(isset($_POST['content']))
{
$mimetype="text/plain";
}else
{
$mimetype=file_type($file['tmp_name']);
}
if (!$dir)
{
error_log("trying to upload to invalid directory");
http_response_code(409);
exit(0);
}
$codename=$database->create_file_node($filename,"",$dir,$mimetype,$user,$overwrite);
if($codename=="error")
{
error_log("could not create file_node in upload.php");
http_response_code(409);
exit(0);
}
if($codename=="filename taken")
{
http_response_code(409);
exit(0);
}
if(isset($_POST['content']))
{
file_put_contents("$storage_root/$codename",$_POST['content']);
}else
{
unlink("$storage_root/$codename");
move_uploaded_file($file['tmp_name'], "$storage_root/$codename");
}
http_response_code(200);
exit(0);
?>
|