-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
executable file
·76 lines (72 loc) · 3.08 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
<?php
require_once("ssas.php");
$ssas = new Ssas();
if(!$ssas -> isUserLoggedIn()){
header("Location: index.php");
echo "redicrect!";
exit();
}
//If a POST occured, try to authenticate
if(isset($_FILES['image'])){
$file_tmp = $_FILES['image']['tmp_name'];
if($file_tmp != ""){
$info = getimagesize($file_tmp);
if (isset($info)) {
if (($info[2] === IMAGETYPE_GIF) || ($info[2] === IMAGETYPE_JPEG) || ($info[2] === IMAGETYPE_PNG)) {
if(filesize($file_tmp) / 1000 < 4096 ){
$image = 'data:' . $info['mime'] . ';base64,' . base64_encode(file_get_contents($file_tmp));
$result = $ssas -> uploadImage($image);
if($result){ header("Location: index.php"); exit(); }
} else $result = "Images can't be more than 4 megabyte";
} else $result = "The uploaded file was not an image";
} else $result = "Info about the uploaded image could not be retrieved";
} else $result = "Please select a file";
}
?>
<?php include 'header.php'; ?>
<?php if($ssas -> isUserLoggedIn()){ ?>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<?php if(isset($result)){ ?>
</br>
<div class="alert alert-danger" role="alert">
<strong>Error!</strong> <?php echo $result; ?>
</div>
<?php } ?>
<form method="post" action="upload.php" enctype="multipart/form-data">
<div class="form-group">
<input id="image-full" type="file" class="form-control" name="image" accept="image/*" required onchange="update_filename('image-full','filename-full')" >
</div>
<div class="form-group has-primary">
<label>Please select an image:</label>
<div class="input-group">
<span class="input-group-btn">
<button
class="btn btn-primary-outline no-border-right" onclick="document.getElementById('image-full').click();return false;">
<i class="fa fa-file-image-o"></i>
</button>
</span>
<input id="filename-full" type="text" class="form-control form-control-primary" placeholder="Select file">
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">Upload</button>
</span>
</div>
</div>
</form>
</div>
</div>
<?php } ?>
<script type="text/javascript">
function update_filename(src, target){
var fullPath = document.getElementById(src).value;
if (fullPath) {
var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
var filename = fullPath.substring(startIndex);
if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
filename = filename.substring(1);
}
document.getElementById(target).value = filename;
}
}
</script>
<?php include 'footer.php'; ?>