/
photos.php
86 lines (70 loc) · 2.56 KB
/
photos.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
80
81
82
83
84
85
86
<?php
require_once('include/User.php');
session_start();
use File\Upload; # declaration, so you can refer to the class as Upload rather than using the fully qualified name
$file_url = null;
$u = $_SESSION['user'];
$us = json_encode($u);
echo "</br>";
echo $us;
echo "</br>";
$usu = json_decode($us);
echo "</br>";
echo $usu->email;
echo "</br>";
if (isset($_POST['upload'])) {
// define the path to the upload folder (DOCUMENT_ROOT er /var/www/adambjorgvins.com/public_html á servernum)
// destination verður "/var/www/adambjorgvins.com/public_html/upload/images/"
$server_path_to_upload_folder = $_SERVER['DOCUMENT_ROOT'] . "/upload/images/" . $u->email . "/"; # Þú þarft að breyta slóð.
if (!file_exists($server_path_to_upload_folder)) {
mkdir($server_path_to_upload_folder);
}
// svo við getum notað class með t.d. move() fallið og getMessage() ogsfrv...
require_once 'include/Upload.php';
// Because the object might throw an exception
try {
// búum til upload object til notkunar. Sendum argument eða slóðina að upload möppunni sem á að geyma skrá
$loader = new Upload($server_path_to_upload_folder);
// köllum á og notum move() fallið sem færir skrá í upload möppu, þurfum að gera þetta strax.
$file_url = "/upload/images/" . $u->email . "/" . $loader->upload();
// köllum á getMessage til að fá skilaboð (error or not).
$result = $loader->getMessages();
} catch (Exception $e) {
echo $e->getMessage(); # ef við náum ekki að nota Upload class
}
}
?>
<!DOCTYPE HTML>
<html>
<head><?php include 'include/assets.php'; ?></head>
<body>
<?php include 'include/header.php'; ?>
<?php
include 'include/database.php';
$db = new database();
?>
<div class="container">
<h1><?php echo $db->currentUserName() ?></h1>
<form action="photos.php" method="post" enctype="multipart/form-data" id="uploadImage">
<div class="file-field input-field">
<div class="btn">
<span>File</span>
<input type="file" name="image" id="image">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload one or more files">
</div>
</div>
<input type="submit" name="upload" id="upload" value="Upload">
</form>
<?php
if(!is_null($file_url )){
?>
<img src="<?php echo $file_url ?>" alt="">
<?php
}
?>
</div>
<?php include 'include/footer.php'; ?>
</body>
</html>