-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwitterCard.php
More file actions
34 lines (32 loc) · 941 Bytes
/
twitterCard.php
File metadata and controls
34 lines (32 loc) · 941 Bytes
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
<?PHP
# stackexchange2php("https://stackoverflow.com/questions/15151051/url-to-a-random-image")
function random_pic($dir = 'imagerotation') {
$files = glob($dir . '/*.jpg');
if (!$files) return false;
$file = array_rand($files);
return $files[$file];
}
function outputImage( $filename ) {
header('Content-Description: File Transfer');
header("Content-type: image/jpeg");
# header('Content-Disposition: attachment; filename='.basename($filename ));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename ));
ob_clean();
flush();
readfile($filename );
exit;
}
// Get a filename
$filename=random_pic();
// Check that a file was found
if (!$filename) {
header('HTTP/1.0 404 Not Found');
die();
}
// Output the image
outputImage( $filename );
?>