-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
69 lines (64 loc) · 1.89 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
<?php
//Remove error reporting in final version!
ini_set('display_errors', 1);
error_reporting(~0);
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']['name'];
//Check that the file is an image file.
if(!exif_imagetype ($file_tmp)){
header("Location: index.php");
echo "redirect!";
exit();
}
$type = pathinfo($file_tmp, PATHINFO_EXTENSION);
$data = file_get_contents($file_tmp);
$image = 'data:image/' . $type . ';base64,' . base64_encode($data);
$result = $ssas -> uploadImage($image);
if($result){
header("Location: index.php");
echo "redicrect!";
exit();
}
}
?>
<?php include 'header.php'; ?>
<?php if($ssas -> isUserLoggedIn()){ ?>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="password">Image:</label>
<input
id="image"
type="file"
class="form-control"
name="image"
accept="image/*"
>
</div>
<button class="btn btn-success" type="submit">Upload</button>
</form>
</div>
</div>
<?php } ?>
<?php if(isset($result) && !$result){ ?>
</br>
<div class="alert alert-danger" role="alert">
<strong>Ups!</strong> Image could not be uploaded.
</div>
<?php } ?>
<?php if(isset($result) && $result){ ?>
</br>
<div class="alert alert-success" role="alert">
<strong>Success!</strong> Image was uploaded!
</div>
<?php } ?>
<?php include 'footer.php'; ?>