-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
75 lines (61 loc) · 2 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
<?php
require_once 'session.php';
require_once 'config.php';
if (!isset($_SESSION['loggedin'])) {
Header("Location: login.php");
}
include 'header.php';
if (isset($_FILES['file'])) {
$username = $_SESSION['username'];
$destination_file = $upload_dir . $username . ".pdf";
$errors = array();
$file_name = $_FILES['file']['name'];
$file_size =$_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
$file_type = $_FILES['file']['type'];
$file_ext = strtolower(end(explode('.', $_FILES['file']['name'])));
$extensions = array("pdf");
if(in_array($file_ext, $extensions)=== false) {
$errors[] = "Extension not allowed, please choose a PDF file.";
}
if($file_size > (5 * 1024 * 1024)) {
$errors[] = 'File size should be less than 5 MB';
}
if(empty($errors) == true) {
// Backup existing file
if(file_exists($destination_file)) {
// Find the number of files that exist for current user
$filecount = count(glob($backup_dir . $username . "*.pdf"));
$backup_file = $backup_dir . $username . "_" . $filecount . ".pdf";
rename($destination_file, $backup_file);
}
// And move new one
$moved = move_uploaded_file($file_tmp, $destination_file);
if( $moved ) {
echo "Successfully uploaded";
} else {
echo "Not uploaded";
}
}
else {
// TODO: Better Error Handling / Printing
foreach ($errors as $index => $error) {
echo $error;
}
}
}
?>
<div class ="container">
<p>Your existing resume will be replaced by the one you upload now.</p>
<br>
<form action="" method="POST" enctype="multipart/form-data">
<input id="file-uploader" name="file" type="file" class="file" data-show-preview="false">
</form>
</div>
<br> <br> <br>
<?php include 'footer.php'; ?>
<script>
$(document).ready(function() {
$("#file-uploader").fileinput({'allowedFileExtensions': ['pdf'], 'maxFileSize': 10240});
});
</script>