forked from spring/spring-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagerotate.php
62 lines (51 loc) · 1.74 KB
/
imagerotate.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
<?php
// We'd like the image to only be up for rotation every 2 minutes
$rot_time = 120;
$time_now = gmmktime();
$time_now -= ($time_now % $rot_time);
header("Etag: $time_now");
if (array_key_exists('HTTP_IF_NONE_MATCH', $_SERVER)) {
$timestamp = (int)$_SERVER['HTTP_IF_NONE_MATCH'];
if ($timestamp + $rot_time > $time_now) {
header("HTTP/1.1 304 Not Modified");
exit();
}
}
include_once('includes/db.php');
// Find suitable images to rotate
$banners_forum = 32;
$sql = '';
$sql .= 'select physical_filename, real_filename, topic_title ';
$sql .= 'from phpbb3_attachments as a, phpbb3_topics as t ';
$sql .= "where t.forum_id = $banners_forum and a.topic_id = t.topic_id ";
$sql .= 'order by rand() limit 1';
$res = mysqli_query($db, $sql);
if ( mysqli_num_rows($res) != 1 ) {
exit();
}
$row = mysqli_fetch_array($res);
// Find suitable images to rotate
$banners_forum = 32;
$sql = '';
$sql .= 'select physical_filename, real_filename, attach_id ';
$sql .= 'from phpbb3_attachments as a, phpbb3_topics as t ';
$sql .= "where t.forum_id = $banners_forum and a.topic_id = t.topic_id ";
$sql .= 'order by rand() limit 1';
$res = mysqli_query($db, $sql);
if (mysqli_num_rows($res) != 1)
exit();
$row = mysqli_fetch_array($res);
$fname = 'phpbb/files/' . $row['physical_filename'];
$picname = $row['real_filename'];
$picext_array = explode('.', strtolower($picname));
$picext = $picext_array[count($picext_array) - 1];
$mimetype = 'image/png';
if ($picext == 'png')
$mimetype = 'image/png';
elseif (($picext == 'jpg') || ($picext == 'jpeg'))
$mimetype = 'image/jpeg';
elseif ($picext == 'gif')
$mimetype = 'image/gif';
header("HTTP/1.1 303 See Other");
header("Content-Type: $mimetype");
header('Location: ' . '/phpbb/download/file.php?id=' . $row['attach_id']);