Created
January 9, 2022 05:03
-
-
Save 0xj0y/fd2b3412d4a55f02ab5670d78f5f135a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("admin_auth_check.php"); | |
$upload_dir = "images/uploads/"; | |
if (!file_exists($upload_dir)) { | |
mkdir($upload_dir, 0777, true); | |
} | |
$file_hash = uniqid(); | |
$file_name = md5('$file_hash' . time()) . '_' . basename($_FILES["fileToUpload"]["name"]); | |
$target_file = $upload_dir . $file_name; | |
$error = ""; | |
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); | |
if (isset($_POST["submit"])) { | |
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); | |
if ($check === false) { | |
$error = "Invalid file"; | |
} | |
} | |
// Check if file already exists | |
if (file_exists($target_file)) { | |
$error = "Sorry, file already exists."; | |
} | |
if ($imageFileType != "jpg") { | |
$error = "This extension is not allowed."; | |
} | |
if (empty($error)) { | |
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { | |
echo "The file has been uploaded."; | |
} else { | |
echo "Error: There was an error uploading your file."; | |
} | |
} else { | |
echo "Error: " . $error; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment