Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=UTF-8');
- header('Cache-Control: no-cache, must-revalidate');
- header('Expires: Sat, 09 Jan 2009 09:09:09 GMT');
- // the folder to read pictures from
- // default: '..' (parent folder)
- $folder = '..';
- // the picture formats to support
- $formats = array(
- 'jpg' => 'image/jpg',
- 'jpeg' => 'image/jpeg',
- 'png' => 'image/png',
- 'gif' => 'image/gif'
- );
- if (substr($folder, -1) != '/')
- {
- $folder .= '/';
- }
- $image = '';
- $files = array();
- $h = opendir($folder);
- while (false !== ($file = readdir($h)))
- {
- $ext = '';
- $info = pathinfo($file);
- if (isset($info['extension']))
- {
- $ext = $info['extension'];
- }
- if (isset($formats[strtolower($ext)]))
- {
- $files[] = $file;
- }
- }
- closedir($h);
- if (count($files) > 0)
- {
- $image = time() % count($files);
- $image = $folder.$files[$image];
- }
- if (strlen($image) <3 )
- {
- die('no pix (sorry bro)');
- }
- // Setting the picture header
- $info = pathinfo($image);
- $ext = $info['extension'];
- $mime = $formats[strtolower($ext)];
- header('Content-Type: ' . $mime);
- // Flushing the image to output
- set_time_limit(5);
- $image = @fopen($image, 'rb');
- while (!feof($image))
- {
- print(@fread($image, 8192));
- ob_flush();
- flush();
- }
- // the missing PHP closing tag
- // (questionmark and greater-than sign)
- // is intentional to prevent image corruption
Advertisement
Add Comment
Please, Sign In to add comment