-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploadpic.php
65 lines (57 loc) · 1.51 KB
/
uploadpic.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
62
63
64
65
<?php
session_start();
if(!isset($_SESSION["userName"]))
{
header("location:index.php");
};
$userName = $_SESSION['userName'];
$connection = mysqli_connect("localhost","root","") or die("Not connected to server");
define("userId","");
mysqli_select_db($connection,'travellog') or die(mysql_error);
$sqlUser = "SELECT id FROM user WHERE userName = '$userName'";
$resultId = mysqli_query($connection,$sqlUser);
if(mysqli_num_rows($resultId)>0)
{
while($rows = mysqli_fetch_assoc($resultId))
{
$userId = $rows['id'];
}
}
//echo "$userId";
if(isset($_POST['submit']))
{
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.',$fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg','jpeg','png');
if(in_array($fileActualExt, $allowed))
{
if($fileError === 0)
{
if($fileSize < 5120000)
{
$fileNameNew = uniqid('',true).".".$fileActualExt;
$fileDestination = 'images/profile/'.$fileNameNew;
$sql = "insert into profilepic(id,location,id_user)values('','$fileDestination','$userId')";
mysqli_query($connection,$sql);
move_uploaded_file($fileTmpName, $fileDestination);
header("location: travellog.php?uploadsuccess");
}
else {
echo "Size exceeded";
}
}
else{
echo "Error";
}
}
else{
echo "Invalid Format";
}
}
?>