-
Notifications
You must be signed in to change notification settings - Fork 0
/
store-image.php
61 lines (55 loc) · 1.63 KB
/
store-image.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include('login/dbconnect.php');
if (isset($_POST['submit'])) {
$usr = $_GET['usr'];
$lat = $_GET['lat'];
$long = $_GET['long'];
$error = "";
$fileName=$_FILES["file"]["name"];
$fileSize=$_FILES["file"]["size"]/1024;
$fileType=$_FILES["file"]["type"];
$fileTmpName=$_FILES["file"]["tmp_name"];
if (isset($_FILES["file"])){
$allowedExts = array("jpg", "jpeg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ($_FILES["file"]["error"] > 0) {
$error .= "Error opening the file<br />";
}
if ( $_FILES["file"]["type"] != "image/gif" &&
$_FILES["file"]["type"] != "image/jpeg" &&
$_FILES["file"]["type"] != "image/png" &&
$_FILES["file"]["type"] != "image/jpg") {
$error .= "Mime type not allowed<br />";
}
if (!in_array($extension, $allowedExts)) {
$error .= "Extension not allowed<br />";
}
if ($_FILES["file"]["size"] > 5242880) {
$error .= "File size shoud be less than 10 MB<br />";
}
if ($error == "") {
$random=rand(1111,9999);
$newFileName=$random.$fileName;
$uploadPath="upload/".$newFileName;
if(move_uploaded_file($fileTmpName,$uploadPath)){
#echo "<br>Successful<br>";
#echo "File Name :".$newFileName;
#echo "<br>";
#echo "File Size :".$fileSize." kb <br>";
#echo "File Type :".$fileType;
#echo "<br>";
$query="INSERT INTO upload (Username,Filename,Latitude,Longitude) VALUES('$usr','$newFileName','$lat','$long')";
mysqli_query($conn,$query);
$true = "true";
header("location:index.php?username=$usr&sent=$true");
}
else
echo $error;
}
else {
echo $error;
}
}
}
?>