forked from codepandaasia/hombenai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
28 lines (25 loc) · 939 Bytes
/
upload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include 'db.php';
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$stmt = $conn->prepare("INSERT INTO photos (filepath) VALUES (?)");
$stmt->bind_param("s", $target_file);
$stmt->execute();
$stmt->close();
echo "The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
} else {
echo "File is not an image.";
}
$conn->close();
?>