-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
79 lines (70 loc) · 2.67 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Created by PhpStorm.
* User: massi
* Date: 24/10/2017
* Time: 21:57
*/
session_start();
require_once 'autoloader.php';
$authenticator = new auth();
$db = dbrepo::getdbinstance();
if(isset($_POST['submit']))
{
$file=$_FILES['file']; // file var die ALLE info hierin opslaat in een array
//echo "<script>console.log('$file')</script>";
$fileName =$_FILES['file']['name'];
$fileTmpName =$_FILES['file']['tmp_name'];
$fileSize =$_FILES['file']['size'];
$fileError =$_FILES['file']['error'];
$fileType =$_FILES['file']['type'];
$fileExt = explode('.', $fileName); // neemt een extensie vd file
$fileActualExt = strtolower(end($fileExt)); // extensie vd file lowercase maken
$allowed = array('jpg','jpeg','png'); //controle op welke files toegelaten zijn op extensie
// controle process
if(in_array($fileActualExt, $allowed))
{
if($fileError===0) // aantal errors bepalen
{
if($fileSize<1000000) // maximum grootte vd file bepalen in kb
{
$userid=$authenticator->getUserid();
$pictureExists=$db->getPictureForUser($userid);
if(!(isset($pictureExists->filepath))) // probleem --> hij wilt niet inserten
{
$filepath = "uploads/" . uniqid('',true). "." . $fileActualExt;
$db->addPicture($userid, $filepath);
}
else
{
$pictureExists=$db->getPictureForUser($userid);
if(!unlink($pictureExists->filepath))
{
echo "You have an error";
}
else
{
header("Location: profile.php?replaceSucces");
}
$filepath = "uploads/" . uniqid('',true) . "." . $fileActualExt;
$db->updatePicture($userid, $filepath);
}
//$fileNameNew=$userid.".".$fileActualExt; // de filenaam maken met een useid+extensie
//$fileDestenation = 'uploads/'.$fileNameNew; // waar de file moet worden upgeload
move_uploaded_file($fileTmpName,$filepath); // de file wordt nu geupload naar waar hij moet
// de tijdelijke plaats van de file wordt naar de eindbestemming gebracht
header("Location: profile.php?uploadsucces");
exit;
}
else
{
echo "Your file is too big!";
}
}
echo "There was an error uploading your file";
}
else
{
echo "You cannot upload files of this type!";
}
}