diff options
-rw-r--r-- | php/.database.php.swp | bin | 16384 -> 16384 bytes | |||
-rw-r--r-- | php/.upload.php.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | php/database.php | 21 | ||||
-rw-r--r-- | php/upload.php | 23 | ||||
-rw-r--r-- | sql/.fileshare.sql.swp | bin | 12288 -> 12288 bytes | |||
-rw-r--r-- | sql/fileshare.sql | 2 |
6 files changed, 33 insertions, 13 deletions
diff --git a/php/.database.php.swp b/php/.database.php.swp Binary files differindex 5193729..eecacf9 100644 --- a/php/.database.php.swp +++ b/php/.database.php.swp diff --git a/php/.upload.php.swp b/php/.upload.php.swp Binary files differnew file mode 100644 index 0000000..e1fc62b --- /dev/null +++ b/php/.upload.php.swp diff --git a/php/database.php b/php/database.php index a46bdd2..cfef823 100644 --- a/php/database.php +++ b/php/database.php @@ -164,6 +164,27 @@ require_once "node.php"; //print count($id); return $id[0]; } + /*returns the file name as it must be in the filesystem*/ + function create_file_node(string $filename): string + { + global $storage_root; + $code=get_random_node_name(""); + if($filename==NULL)return false; + $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; + } function are_linked(int $directory_id,int $node_id): bool { $prepare=$this->pdo->prepare("select node_id diff --git a/php/upload.php b/php/upload.php index d9110c7..bd72b6b 100644 --- a/php/upload.php +++ b/php/upload.php @@ -1,22 +1,21 @@ <?php +require_once "database.php" +require_once "configuration.php" -if (!array_key_exists('uf', $_FILES)) { +if (!isset( $_POST["filename") || !isset($_POST["the_file"]) +{ http_response_code(400); - exit(); + error_log("someone tried to upload something impropperly"); + exit(1); } -$file = $_FILES['uf']; +$file = $_POST["the_file"]; +$filename= $_POST["filename"]; -if (file['error'] != 0) { - http_response_code(400); - exit(); -} - -$m = md5_file($file['tmp_name']); - -copy($file['tmp_name'], "screen/$m.png"); +$codename=create_file_node($filename); -echo "http://india.fmi.fail/screen/$m.png"; +copy($file['tmp_name'], "$storage_root/$codename"); +echo $codename; ?> diff --git a/sql/.fileshare.sql.swp b/sql/.fileshare.sql.swp Binary files differindex 504ee7e..963a386 100644 --- a/sql/.fileshare.sql.swp +++ b/sql/.fileshare.sql.swp diff --git a/sql/fileshare.sql b/sql/fileshare.sql index 247a21e..4cd748a 100644 --- a/sql/fileshare.sql +++ b/sql/fileshare.sql @@ -5,7 +5,7 @@ create table nodes ( type varchar(20) not null default 'data', name varchar(100) not null default 'no name', note varchar(200) not null default "", - code char(30) not null default "error", + code varchar(100) not null default "error", primary key (node_id) ); |