OLD | NEW |
---|---|
(Empty) | |
1 <?php | |
2 # Returns a cacheable image randomly. | |
yhirano
2017/05/12 10:30:43
Isn't this comment (and filename) confusing? The t
hiroshige
2017/05/12 17:14:51
Maybe. I chose the name because this is used simil
| |
3 | |
4 require_once '../../resources/portabilityLayer.php'; | |
5 | |
6 if (!sys_get_temp_dir()) { | |
kouhei (in TOK)
2017/05/11 18:22:08
I'm not sure if we are guaranteed to get same temp
| |
7 echo "FAIL: No temp dir was returned.\n"; | |
8 exit(); | |
9 } | |
10 | |
11 $id = intval($_GET['id']); | |
12 $countFilename = sys_get_temp_dir() . "/random-cached-image." . $id . ".tmp"; | |
13 $count = 0; | |
14 if (file_exists($countFilename)) { | |
15 $count = file_get_contents($countFilename); | |
16 } | |
17 $count += 1; | |
18 file_put_contents($countFilename, $count); | |
19 | |
20 # Images with different dimensions. | |
21 $imageFilenames = array( | |
22 '../../resources/square20.png', | |
23 '../../resources/square100.png', | |
24 '../../resources/square200.png' | |
25 ); | |
26 | |
27 header("Content-type: image/png"); | |
28 header("Cache-control: max-age=60000"); | |
29 header("ETag: 98765"); | |
30 | |
31 readfile($imageFilenames[$count % count($imageFilenames)]); | |
32 ?> | |
OLD | NEW |