andylord Posted June 20, 2009 Share Posted June 20, 2009 <?php @error_reporting (E_ALL ^ E_NOTICE); /* USER SETTINGS */ $image_dir = "upload/files"; /* if true, gif thumbnails are used*/ $use_gifs = true; /* SETUP, DEFAULTS, and CHECK SETTINGS*/ $view = (isset($_REQUEST['view'])) ? $_REQUEST['view'] : ""; // Read all files in $image_dir if (!isset($image)) { $image = phppg_recursive_listdir($image_dir); } else { array_walk ($image, 'phppg_add_image_dir'); } // SECURITY CHECK : Requested $view must contain the REAL PATH of '$image_dir' if ($view) { $image_dir_path = realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $image_dir); // REALPATH to image directory $view_dir_path = dirname(realpath($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/" . $view . ".jpg")); // REALPATH to the image file if (!$image_dir_path || !$view_dir_path || !stristr($view_dir_path, $image_dir_path)) { die("BAD REQUEST<br>There has been an error - please <a href=\"" . $_SERVER['PHP_SELF'] . "\">go back</a>"); } } // Remove extensions array_walk ($image, 'phppg_remove_extension'); $temp_image = array_unique($image); $image = array(); $i = 0; foreach ($temp_image as $v) { /* reset array keys */ $image[$i] = $v; $i++; } // Defaults if (!isset($view) || !$view) $view = $image[0]; /* DISPLAY - large image*/ if ($view && (file_exists($view . ".jpg"))) { $currKey = array_keys ($image, $view); ?> <?php $i = 0; foreach($image as $v) { print("\t\t<a href=\"javascript:popup('andys-cop-help.com/" . $v . ".jpg','')\"><img src=\"" . $v . ".gif\" alt=\"\" height=\"90\" width=\"90\"></a>\n"); $i++; } ?> <?php } /* FUNCTIONS ** array_walk() uses this to remove extensions from array ** @param value (string) array value passed by reference ** @param key (string) array key */ function phppg_remove_extension(&$value, $key) { $value = preg_replace(array("/.gif/i", "/.jpg/i"), "", $value); } function phppg_add_image_dir(&$value, $key) { global $image_dir; $value = $image_dir . "/" . $value; } /**array phppg_recursive_listdir( (string) base) ** Recursively searches directory and returns an array ** @param base (string) base */ function phppg_recursive_listdir($base) { static $filelist = array(); static $dirlist = array(); if(is_dir($base)) { $dh = opendir($base); while (false !== ($dir = readdir($dh))) { if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..') { $subbase = $base ."/". $dir; $dirlist[] = $subbase; $subdirlist = phppg_recursive_listdir($subbase); } elseif(is_file($base ."/". $dir) && $dir !== '.' && $dir !== '..') { $filelist[] = $base ."/". $dir; } } closedir($dh); } $array['dirs'] = $dirlist; $array['files'] = $filelist; //return $array; return $filelist; } ?> ok i have this code here but when i use it it isnt showing the images wondering if any of you know why this is ? Link: http://andys-cop-help.com/Showimages.php Quote Link to comment https://forums.phpfreaks.com/topic/163053-solved-directory-images/ Share on other sites More sharing options...
fnairb Posted June 20, 2009 Share Posted June 20, 2009 The path is incorrect or the files are not there. THere is no file http://andys-cop-help.com/upload/files/Blackimage.gif Quote Link to comment https://forums.phpfreaks.com/topic/163053-solved-directory-images/#findComment-860358 Share on other sites More sharing options...
mattal999 Posted June 20, 2009 Share Posted June 20, 2009 Well, I am just wondering how PHP gets a list of all the files in the DIR when it returns a 403 error. And yes, the images doesn't exist. Quote Link to comment https://forums.phpfreaks.com/topic/163053-solved-directory-images/#findComment-860359 Share on other sites More sharing options...
andylord Posted June 20, 2009 Author Share Posted June 20, 2009 ah dam they are gifs, but i cant see why it isnt showing them as gifs now :S Quote Link to comment https://forums.phpfreaks.com/topic/163053-solved-directory-images/#findComment-860361 Share on other sites More sharing options...
mattal999 Posted June 20, 2009 Share Posted June 20, 2009 They show as .jpgs. Just thought i'd let you know. 150x150 pixels to be precise. Quote Link to comment https://forums.phpfreaks.com/topic/163053-solved-directory-images/#findComment-860363 Share on other sites More sharing options...
andylord Posted June 20, 2009 Author Share Posted June 20, 2009 ah its me being stupid, i forgot to put my thumbnails on in gifs lol Quote Link to comment https://forums.phpfreaks.com/topic/163053-solved-directory-images/#findComment-860365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.