aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradam <adam@>2021-02-12 13:24:33 +0200
committeradam <adam@>2021-02-12 13:24:33 +0200
commit077cab20146bf7cb26c330465fbd56cc0e0ddada (patch)
treecf686f7f1829b4da77f32cb5031fec16504efca4
parent527301b44e44e994c89ba4db47a49e37eaef4d1b (diff)
downloadfileup-077cab20146bf7cb26c330465fbd56cc0e0ddada.tar.gz
asdf
-rw-r--r--php/database.php8
-rw-r--r--php/upload.php18
-rw-r--r--sql/fileshare.sql9
3 files changed, 25 insertions, 10 deletions
diff --git a/php/database.php b/php/database.php
index cfef823..b1e0419 100644
--- a/php/database.php
+++ b/php/database.php
@@ -168,22 +168,22 @@ require_once "node.php";
function create_file_node(string $filename): string
{
global $storage_root;
- $code=get_random_node_name("");
- if($filename==NULL)return false;
+ $code=$this->get_random_node_name("");
+ if($filename==NULL)return "error";
$prep=$this->pdo->prepare("insert into nodes(is_directory,relative_path,name,code)
values(false,:root,:name,:code)
");
$prep->bindParam(':name',$filename);
$prep->bindParam(':root',$storage_root);
-
$prep->bindParam(':code',$code);
+
if($prep->execute()==false)
{
error_log("could not upload file");
/*not so quiet error*/
return "error";
}
- return code;
+ return $code;
}
function are_linked(int $directory_id,int $node_id): bool
{
diff --git a/php/upload.php b/php/upload.php
index 42a8bf6..b6cd335 100644
--- a/php/upload.php
+++ b/php/upload.php
@@ -2,20 +2,26 @@
require_once "database.php";
require_once "configuration.php";
-if (!isset( $_POST["filename"]) || !isset($_POST["the_file"]))
+if (!isset( $_POST["filename"]) || !isset($_FILES["the_file"]))
{
http_response_code(400);
error_log("someone tried to upload something impropperly");
exit(1);
}
-$file = $_POST["the_file"];
+$file = $_FILES["the_file"];
$filename= $_POST["filename"];
-$codename=create_file_node($filename);
-
-copy($file['tmp_name'], "$storage_root/$codename");
+$codename=$database->create_file_node($filename);
+if($codename=="error")
+{
+ http_response_code(400);
+ exit(0);
+}
+error_log($file['tmp_name']);
+move_uploaded_file($file['tmp_name'], "$storage_root/$codename");
-echo $codename;
+http_response_code(200);
+exit(0);
?>
diff --git a/sql/fileshare.sql b/sql/fileshare.sql
index 4cd748a..ed48696 100644
--- a/sql/fileshare.sql
+++ b/sql/fileshare.sql
@@ -1,3 +1,12 @@
+/*BEWARE!*/
+drop table if exists nodes;
+drop table if exists users;
+drop table if exists node_access;
+drop table if exists node_links;
+
+
+
+
create table nodes (
node_id int not null auto_increment,
is_directory boolean default false,