-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathphoto_upload.php
73 lines (64 loc) · 1.85 KB
/
photo_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
<?php
require('app.php');
if(!PupilAuth::isLoggedIn()) {
header( 'Location: index.php' ) ;
exit;
}
require('templates/header.php');
?>
<div class="ui segment">
<h1>Photo upload result:</h1>
<p>
<?php
$photo_path = "";
if($_POST['photo_type'] == "current") {
$photo_path = "current";
}else if($_POST['photo_type'] == "baby") {
$photo_path = "baby";
}else {
die;
}
if($_FILES['photo']['name'])
{
//if no errors...
if(!$_FILES['photo']['error'])
{
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file
$valid_file = true;
if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
{
$valid_file = false;
echo 'Your file\'s size is to large.';
}
if($valid_file)
{
$tmp_path = 'media/'.$photo_path.'/'.$User->rollnumber.'.JPG';
if(file_exists($tmp_path)) {
unlink($tmp_path);
}
move_uploaded_file($_FILES['photo']['tmp_name'], $tmp_path);
if($photo_path == "current") {
DB::update('pupils', array('currentphoto' => $tmp_path), 'rollnumber=%s', $User->rollnumber);
}else if($photo_path == "baby") {
DB::update('pupils', array('babyphoto' => $tmp_path), 'rollnumber=%s', $User->rollnumber);
}
echo 'Your file was uploaded successfully.';
}else {
echo 'failed';
}
}
//if there is an error...
else
{
//set that to be the returned message
echo 'Your upload triggered the following error: '.$_FILES['photo']['error'];
}
}
?>
<br/><a href="/photos.php">Click here to go back</a>
</p>
</div>
<?php
require('templates/footer.php');
?>