From f0cddfaeb09aceea2330cb896fc4dd5906aebd16 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 14 Feb 2021 12:19:10 +0100 Subject: [PATCH] w3 schools image upload --- .gitignore | 3 +++ index.php | 13 +++++++++++++ table.sql | 6 ++++++ upload.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .gitignore create mode 100644 index.php create mode 100644 table.sql create mode 100644 upload.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..878e219 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +uploads/ +*.db + diff --git a/index.php b/index.php new file mode 100644 index 0000000..cce4cbd --- /dev/null +++ b/index.php @@ -0,0 +1,13 @@ + + + + + +
+ Select image to upload: + + +
+ + + diff --git a/table.sql b/table.sql new file mode 100644 index 0000000..1c7167b --- /dev/null +++ b/table.sql @@ -0,0 +1,6 @@ +CREATE TABLE Users ( + ID INT PRIMARY KEY NOT NULL, + Username TEXT NOT NULL, + Password TEXT NOT NULL +); + diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..be58a3c --- /dev/null +++ b/upload.php @@ -0,0 +1,50 @@ + + 500000) { + echo "Sorry, your file is too large."; + $uploadOk = 0; +} + +// Allow certain file formats +if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" + && $imageFileType != "gif" ) { + echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; + $uploadOk = 0; +} + +// Check if $uploadOk is set to 0 by an error +if ($uploadOk == 0) { + echo "Sorry, your file was not uploaded."; +// if everything is ok, try to upload file +} else { + if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { + echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded."; + } else { + echo "Sorry, there was an error uploading your file."; + } +} +?>