-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.php
53 lines (46 loc) · 1.31 KB
/
example.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
<?php
session_start();
if(!isset($_SESSION['userid'])) {
$_SESSION['userid'] = rand();
}
if(!isset($_COOKIE['userid'])) {
setcookie('userid', rand(), strtotime("+1 week"), '/');
}
?>
<!-- odr -->
<link rel="stylesheet" href="odr/style.css" type="text/css" />
<script type="text/javascript" src="odr/odr.js.php"></script>
<!-- /odr -->
Hi! Here's a simple user ID generated
for you and stored as session: <?=$_SESSION['userid']?>,
and here's a simple user ID stored as
cookie: <?=$_COOKIE['userid']?>. It shall change
every time the demo resets.
<hr/>
<?php
$db = new mysqli('localhost', 'root', '1708', 'opendemoreset');
if($_SERVER['REQUEST_METHOD']=='POST' AND $_FILES['file']['size']) {
if(strtolower(end(explode(".", $_FILES['file']['name'])))=='jpg') {
$filename = 'uploads/'.uniqid().'.jpg';
move_uploaded_file($_FILES['file']['tmp_name'], $filename);
$db->query("INSERT INTO images VALUES ('', '$filename')");
} else {
echo '<p>JPG files only!</p>';
}
}
?>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" />
</form>
<hr/>
<?php
$qry = $db->query("SELECT * FROM images ORDER BY id DESC LIMIT 10");
if($qry->num_rows) {
while($row = $qry->fetch_array()) {
echo '<img src="'.$row['image'].'" /><br/>';
}
} else {
echo '<p>No images sent, yet.</p>';
}
?>