-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupload.php
59 lines (40 loc) · 1.61 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
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
include_once "./server/loginService.php";
include_once "./server/loginSQL.php";
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$tmp = explode('.', $_FILES['image']['name']);
$file_ext = strtolower(end($tmp));
//$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
if(!session_start())
{
session_start();
}
$file_name = $_SESSION['UserId'] . "." . $file_ext;
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="Extension not allowed. Please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[] = "File size must be excately 2 MB.";
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"images/".$file_name);
$profilePicture = 'images/' . $file_name;
$loginWebService = new LoginWebService();
$loginWebService->uploadProfilePicture($_SESSION['UserId'], $profilePicture);
$loginWebService -> updateDisplayPic($_SESSION['UserId'], 0);
echo "File successfully uploaded.";
header("Location: mainpage.php ");
}else{
print_r($errors);
}
}
?>