-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
46 lines (39 loc) · 1.3 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
include "openconn.php";
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
if (isset($_POST['avatarSubmit'])){
$avatar = $_FILES['avatar'];
$avatarName = $_FILES['avatar']['name'];
$avatarTmpName = $_FILES['avatar']['tmp_name'];
$avatarSize = $_FILES['avatar']['size'];
$avatarError = $_FILES['avatar']['error'];
$avatarType = $_FILES['avatar']['type'];
$avatarExt = explode('.', $avatarName);
$avatarActualExt = strtolower(end($avatarExt));
$allowed = array('jpg', 'jpeg', 'png'); //types of files allowed to upload
if (in_array($avatarActualExt, $allowed)) {
if ($avatarError == 0) {
if ($avatarSize < 1000000){
$avatarNameNew = uniqid().".".$avatarActualExt;
$avatarDestination = 'avatar/'.$avatarNameNew;
move_uploaded_file($avatarTmpName, $avatarDestination);
$insertAvatar = " insert into quikChef_avatar(name, user_username) values('$avatarNameNew', '" . $_SESSION['username'] . "')";
mysqli_query($conn, $insertAvatar);
header("Location: initialPage.php");
}
else {
echo "Your file is to big!";
}
}
else {
echo "There was an error uploading your file!";
}
}
else {
echo "You cannot upload files of this type!";
}
}
?>