Jump to content

[SOLVED] Directory images


andylord

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/163053-solved-directory-images/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.