2097152) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow only JPG, JPEG, PNG, GIF
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if (!in_array($imageFileType, ['jpg', 'jpeg', 'png', 'gif'])) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// If all checks pass, upload file
if ($uploadOk) {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
// Insert into database
$query = "INSERT INTO gallery (image_url) VALUES (?)";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, "s", $target_file);
if (mysqli_stmt_execute($stmt)) {
echo "Image uploaded successfully!";
} else {
echo "Error uploading image.";
}
mysqli_stmt_close($stmt);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
?>