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/fileManagerFiles/download.php | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 public/fileManagerFiles/download.php (limited to 'public/fileManagerFiles') 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"); +} +?> -- cgit v1.3.1