// Proses upload fileif ($_SERVER["REQUEST_METHOD"] == "POST") { $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $fileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); // Cek jika file adalah gambar atau bukan if (isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if ($check !== false) { echo "File is an image - " . $check["mime"] . ".
"; } else { echo "File is not an image.
"; $uploadOk = 0; } } // Cek jika file sudah ada if (file_exists($target_file)) { echo "Sorry, file already exists.
"; $uploadOk = 0; } // Cek ukuran file if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large.
"; $uploadOk = 0; } // Hanya izin file tertentu yang diizinkan if ($fileType != "jpg" && $fileType != "png" && $fileType != "jpeg" && $fileType != "gif") { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.
"; $uploadOk = 0; } // Cek jika $uploadOk adalah 0 karena kesalahan if ($uploadOk == 0) { echo "Sorry, your file was not uploaded.
"; // Jika semuanya baik, coba 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.
"; } }}<!DOCTYPE html>