From d5cb8fd65d5c86c8627d3728d3aec7e1ae6ed4dd Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Wed, 12 Apr 2023 16:26:30 +0200 Subject: Initial commit with working app --- public/fileManager.php | 284 +++++++++++++++++++++++++++++++++++ public/fileManagerFiles/download.php | 63 ++++++++ public/index.php | 71 +++++++++ 3 files changed, 418 insertions(+) create mode 100644 public/fileManager.php create mode 100644 public/fileManagerFiles/download.php create mode 100644 public/index.php (limited to 'public') diff --git a/public/fileManager.php b/public/fileManager.php new file mode 100644 index 0000000..bdd52f1 --- /dev/null +++ b/public/fileManager.php @@ -0,0 +1,284 @@ + $v) + { + if ( $v == 0 ) + { + $id = random_str(); + $new_name = $uploaddir . $id; + var_dump($new_name); + $temp_name = $_FILES['files']['tmp_name'][$k]; + $file_name = $_FILES['files']['name'][$k]; + + if ( file_exists($new_name) ) { + $_SESSION["communicates"]['fileError'] = "Plik z podaną nazwą $new_name już istnieje na serwerze"; + } + else { + if ( move_uploaded_file($temp_name, $new_name) ) { + $success[] = $_FILES['files']['name'][$k]; + $fd = fopen($uploaddir . "../downloads.txt", 'a'); + $description = $_POST["text$i"];// != "" ? $_POST["text$i"] : "brak"; + fwrite($fd, "$id;$file_name;$uploaddir;$description\n"); + fclose($fd); + } else { + $error[] = $_FILES['files']['name'][$k]; + } + } + } + $i++; + } + if ( count($error) ) + $_SESSION["communicates"]['uploadError'] = "Nie udało się załadować następujących plików: " . implode(", ", $error); + else if ( count($success) ) + $_SESSION["communicates"]['uploadSuccess'] = "Udało się załadować następujące pliki: " . implode(", ", $success); + } else + { + switch ($_FILES['fileName']['error']) + { + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + $_SESSION["communicates"]["uploadFileError"] = "Przekroczony maksymalny rozmiar pliku!"; + break; + case UPLOAD_ERR_PARTIAL: + $_SESSION["communicates"]["uploadFileError"] = "Odebrano tylko część pliku!"; + break; + case UPLOAD_ERR_NO_FILE: + $_SESSION["communicates"]["uploadFileError"] = "Plik nie został pobrany!"; + break; + case UPLOAD_ERR_NO_TMP_DIR: + $_SESSION["communicates"]["uploadFileError"] = "Brak dostępu do katalogu tymczasowego!"; + break; + case UPLOAD_ERR_CANT_WRITE: + $_SESSION["communicates"]["uploadFileError"] = "Nie udało się zapisać pliku na dysku serwera!"; + break; + case UPLOAD_ERR_EXTENSION: + $_SESSION["communicates"]["uploadFileError"] = "Ładowanie pliku przerwane przez rozszerzenie PHP!"; + break; + default: + $_SESSION["communicates"]["uploadFileError"] = "Nieznany typ błędu!"; + } + } + header("Location: fileManager.php"); + exit(); +} +?> + + + + + + + + + + + + + + fileManager + + + +
+
+ + + +

+ +
+

+ $value) + echo "$value"; + ?> +

+
+
+

Uploaded files

+ {$arr[1]}"; + if($arr[3] !== "") + echo "
{$arr[3]}
"; + else + echo ""; + } + } + fclose($fd); + } else + echo 'Something went wrong'; + ?> + + + + + + diff --git a/public/fileManagerFiles/download.php b/public/fileManagerFiles/download.php new file mode 100644 index 0000000..1b7731c --- /dev/null +++ b/public/fileManagerFiles/download.php @@ -0,0 +1,63 @@ +Server error! Mail admin at admin@{$_SERVER['HTTP_HOST']}"; + header("Location: ../fileManager.php"); + return; + } + $found = false; + while (!feof($fd)) + { + $line = trim(fgets($fd)); + $arr = explode(";", $line); + if ( count($arr) == 4 ) + { + if ( $id === $arr[0] ) + { + $found = true; + $path = $arr[2]; + $name = $arr[1]; + break; + } + } + } + + //var_dump($found); + //var_dump($path . $id); + //var_dump(!file_exists($path . $id)); + if ( !$found || !file_exists($path . $id) ) + { + $_SESSION["communicates"]["fileError"] = "No file with given id!"; + return; + } + $fd = fopen($path . $id, "r"); + $size = filesize($path . $id); + //$contents = fread($fd, $size); + fclose($fd); + + header("Content-Type: application/octet-stream"); + header("Content-Length: $size;"); + header('Content-Disposition: attachment; filename="'.$name.'"'); + echo file_get_contents($path . $id); + //echo $contents; +} + +if ( !empty($_GET['fileid']) ) + send($_GET['fileid']); +else +{ + $_SESSION["communicates"]["fileError"] = "No file id given!"; + header("Location: ../fileManager.php"); +} +?> diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..dab9201 --- /dev/null +++ b/public/index.php @@ -0,0 +1,71 @@ + + + + + + + + sessionLogin + + + + +
+
+
+

+ +
+
+ + + -- cgit v1.3.1