diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-15 14:47:37 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-15 14:47:37 +0200 |
commit | 7fe813121b2e6d95ad6e86eeaf12ed58dc2ff729 (patch) | |
tree | 4088b7f5ca5b1368794a81032ea52ae221c2287f /php/upload.php | |
parent | 8b1406ede7389c9e50fa0c095be7a8524d265c8c (diff) | |
parent | 7532e744e0be43657cafffce171f875ffe94fc3f (diff) | |
download | fileup-7fe813121b2e6d95ad6e86eeaf12ed58dc2ff729.tar.gz |
Merge branch 'master' of https://github.com/alexvitkov/india
Diffstat (limited to 'php/upload.php')
-rw-r--r-- | php/upload.php | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/php/upload.php b/php/upload.php index 04f2214..f3ef550 100644 --- a/php/upload.php +++ b/php/upload.php @@ -6,7 +6,9 @@ require_once "user.php"; require_once "node.php"; session_start(); -if (!isset( $_POST["filename"]) || !isset($_FILES["the_file"]) || !isset($_POST['parent_directory']) || !isset($_POST['overwrite'])) +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); @@ -18,10 +20,17 @@ $filename=$_POST["filename"]; $parent_directory=$_POST["parent_directory"]; $user=$_SESSION['user_object']; $homedir=$user->home_directory; -$mimetype=file_type($file['tmp_name']); $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"); @@ -41,8 +50,14 @@ if($codename=="filename taken") http_response_code(409); exit(0); } -unlink("$storage_root/$codename"); -move_uploaded_file($file['tmp_name'], "$storage_root/$codename"); +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); |