From: joni moas Date: Fri, 27 Nov 2020 16:57:45 +0000 (+0200) Subject: Create index.php X-Git-Url: https://reisub.nsupdate.info/git/?p=webFTP.git%2F.git;a=commitdiff_plain;h=a8f8c1335b85d3c77d3f7e9f10fd8dd9a6ffb1d7 Create index.php --- diff --git a/index.php b/index.php new file mode 100644 index 0000000..6c5ba43 --- /dev/null +++ b/index.php @@ -0,0 +1,213 @@ + 1) { + array_pop($_SESSION["path"]); + } +} + +function endFTP() +{ + ftp_close($GLOBALS["conn_id"]); +} + +function getFileTable($directory) +{ + ob_clean(); + echo "Current Path: " . ftp_pwd($GLOBALS["conn_id"]) . " "; + + $contents = + ftp_nlist($GLOBALS["conn_id"], $directory); + + //table header + echo ""; + echo ""; + + //upload file / go up row + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + + foreach ($contents as $file) { + //file/folder row + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + echo "
NameAction
"; + echo ""; + echo ""; + echo ""; + echo "
"; + echo ""; + echo ""; + echo "
$file"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
"; + echo "
"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
"; + echo "
"; +} + +function downloadFile($file) +{ + if (ftp_get($GLOBALS["conn_id"], basename($file), basename($file), FTP_BINARY)) { + if (basename($file)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="' . basename(substr(basename($file), 1)) . '"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize(substr(basename($file), 1))); + readfile(substr(basename($file), 1)); + unlink(basename($file)); + } + } else { + echo "There was a problem\n"; + } +} + +function uploadFile($temp_name, $target_file) +{ + if (startFTP()) { + if (move_uploaded_file($temp_name, $target_file)) { + if (ftp_put($GLOBALS["conn_id"], $target_file, $target_file, FTP_BINARY)) { + unlink(basename($target_file)); + getFileTable($_SESSION["path"][count($_SESSION["path"]) - 1]); + } else { + echo "There was a problem while uploading $target_file\n"; + } + } + endFTP(); + } else { + echo "Sorry, there was an error uploading your file."; + } +} + +function deleteFile($file) +{ + if (ftp_delete($GLOBALS["conn_id"], $file)) { + return true; + } + echo "File not deleted!"; +} + +function getLoginForm() +{ + echo "
"; + echo "Host: "; + echo "

"; + echo "Name: "; + echo "

"; + echo "Password: "; + echo "

"; + echo ""; + echo "
"; +}