Skip to content

Instantly share code, notes, and snippets.

@hklcf
Last active September 20, 2016 01:55
Show Gist options
  • Save hklcf/917c331f9b2ce6c2bfb841892732068d to your computer and use it in GitHub Desktop.
Save hklcf/917c331f9b2ce6c2bfb841892732068d to your computer and use it in GitHub Desktop.
<?php
$type = array('jpg', 'jpeg', 'gif', 'png');
$dir = './pic';
if($handle = opendir($dir)) {
while(false !== ($file = readdir($handle))) {
$ext = pathinfo($file);
$ext = $ext['extension'];
if($file != "." && $file != ".." && in_array($ext, $type)) {
$files[] = $file;
}
}
closedir($handle);
}
$name = rand(0, count($files) - 1);
if(@$_GET['action'] == '.gif') {
$randfile = $dir.'/'.trim($files[$name]);
} else {
$randfile = "noavatar.gif";
}
$file_ct = mime_content_type($randfile);
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: $file_ct");
readfile($randfile);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment