Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $target_dir = "uploads/";
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- $new_target_file = $target_dir . "banner." . pathinfo($target_file, PATHINFO_EXTENSION);
- $uploadOk = 1;
- $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
- //Check if file exists
- if (file_exists($target_file)) {
- echo "Sorry, file already exists.<br>";
- $uploadOk = 0;
- }
- //Check file size
- if ($_FILES["fileToUpload"]["size"] > 5000000) {
- echo "Sorry, your file is too large. (5mb)<br>";
- $uploadOk = 0;
- }
- //Allow certain file formats
- if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG") {
- echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.<br>";
- $uploadOk = 0;
- }
- if (isset($_POST["submit"])) {
- $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
- if ($check !== false) {
- echo "File is an image - " . $check["mime"] . ".<br>";
- $uploadOk = 1;
- } else {
- echo "File is not an image.<br>";
- $uploadOk = 0;
- }
- }
- if ($uploadOk == 0) {
- echo "Sorry, your file was not uploaded.";
- } else {
- if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $new_target_file)) {
- echo "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.<br>";
- } else {
- echo "Sorry, there was an error uploading your file.<br>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement