Created
February 8, 2017 00:34
-
-
Save KOUISAmine/4ecc6ea0655a93f328cede74401569fb to your computer and use it in GitHub Desktop.
Simple upload en drag and drop avec MySQLi
This file contains 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 | |
$conn = new mysqli('localhost', 'root', '', 'image'); | |
if(ISSET($_POST['save'])){ | |
if($_FILES['image']['name'] == ""){ | |
echo '<script>alert("Veuillez selectionner une image")</script>'; | |
echo '<script>window.location = "index.php"</script>'; | |
}else{ | |
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); | |
$image_name = addslashes($_FILES['image']['name']); | |
$image_size = getimagesize($_FILES['image']['tmp_name']); | |
move_uploaded_file($_FILES["image"]["tmp_name"], "upload/". $_FILES["image"]["name"]); | |
$location = $_FILES["image"]["name"]; | |
$stmt = $conn->prepare("INSERT INTO `photo` (photo_name) VALUES(?)") or die(mysqli_error()); | |
$stmt->bind_param("s", $location); | |
if($stmt->execute()){ | |
$stmt->close(); | |
$conn->close(); | |
echo '<script>alert("Image Telecharger avec succes")</script>'; | |
echo '<script>window.location = "index.php"</script>'; | |
}else{ | |
echo '<script>alert("Error")</script>'; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment