Skip to content

Instantly share code, notes, and snippets.

@KOUISAmine
Created February 8, 2017 00:34
Show Gist options
  • Save KOUISAmine/4ecc6ea0655a93f328cede74401569fb to your computer and use it in GitHub Desktop.
Save KOUISAmine/4ecc6ea0655a93f328cede74401569fb to your computer and use it in GitHub Desktop.
Simple upload en drag and drop avec MySQLi
<?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