Въпрос !

sniperbg

Registered
здравейте как мога да направя така че в един пхп файл да ми извежда картинките от някфи папки и под папки и да показва картинките и адреса към тях ?
 
Код:
<?php
ini_set('arg_separator.output','&');


$base_dir = dirname(__FILE__); // Base Directory we recommend dirname(__FILE__),
$thumb_dir = '__thumbs__'; // Sets the Cache directory for thumbs
$big_dir = '__big__'; // Sets the Cache directory for bigs
$qaulity = 100; // Sets the JPEG Compression Qaulity
$thumb_width = 120; // Specifies Thumb Width
$thumb_height = 90; // Specifies Thumb Hieght (Value of 'auto' will automatically select the height based on the images width while preserving i'ts aspect ratio)
$big_width = 720; // Specifies Big Width (Size of image's width when clicked on)
$big_height = 'auto'; // Specifies Big Height (Size of image's height when clicked one) 'auto' will do the same as before
$cache = true;
$e_error = true; // Would you like error reporting ?

$filestyle = "padding:15px;float:left; background-color: #d6e0ec; border: 1px solid #0072bc; margin:5px;";
$folderstyle = "padding:15px;float:left; background-color: #fce6d4; border: 1px solid #ffc20e; margin:5px; ";

/* END SETTINGS */

/* resolve ../ and ./ and extra /'s */
$base_dir = realpath($base_dir);

/* PHP 4 does not have stripos, let's create it */
if (!function_exists('stripos')) {
	function stripos($haystack, $needle) {
			return strpos (strtolower($haystack), strtolower($needle));
		}
}


if (isset($_GET['folder'])) {
	$folder = realpath($base_dir . '/' . urldecode($_GET['folder']));
} 

if (!@$folder or @$folder=='') {
	$folder = $base_dir;
}

if (isset($_GET['file'])) {
	$file = realpath($folder . '/' . urldecode($_GET['file']));
	/* Set folder to folder of file */
	$folder = dirname($file);
	/* set file to file name of the file */
	$file = basename($file);
}

/* Something went wrong */
if (!$folder) {
	if ($e_error){die( '<hr /><h2 style="color:red;">Error in '.basename($_SERVER['SCRIPT_FILENAME']).'</h2><p>Could not find folder, or no access.</p><hr />');}
}
/* Check if base_dir is set correctly */
if ($base_dir == false) { 
	if ($e_error){die( '<hr /><h2 style="color:red;">Error in '.basename($_SERVER['SCRIPT_FILENAME']).'</h2><p>Cannot locate $basedir, please check your configuration settings.</p><hr />');}
}
/* Check if $folder string is smaller then $base_dir */
if (strlen($base_dir) > strlen($folder)) { 
	if ($e_error){die( '<hr /><h2 style="color:red;">Error in '.basename($_SERVER['SCRIPT_FILENAME']).'</h2><p>Could not find folder, or no access.</p><hr />');}
}
/* check if outside $base_ dir */
if (substr($folder,0,strlen($base_dir)) != $base_dir) {
	if ($e_error){die( '<hr /><h2 style="color:red;">Error in '.basename($_SERVER['SCRIPT_FILENAME']).'</h2><p>Folder outside base dir</p><hr />');}
}

function resize_image($source, $width, $height='auto', $string =''){
		/* set old width and height */
		@$oldwidth = imagesx($source);
		@$oldheight = imagesy($source);
		
		/* If the source image is invalid create a ? mark image */
		if ($oldwidth == 0 or $oldheight == 0) {
					$height = $width/1.33;
					$dest = imagecreatetruecolor(5,8);
					imagefill($dest,1,1,imagecolorallocate($dest,255,255,255));
					imagestring($dest,1,0,0,"?", imagecolorallocate($dest, 0,0,0));
					return resize_image ($dest,$width,$height);

		}
		
		/* Find aspect ratio */
		$ar =  $oldheight/$oldwidth;
	
		/* if height is auto set it to fit the aspect ratio of width */
		if ($height == 'auto') {
			$height = $width*$ar;
		}
		
		/* Create new image using the new size */
		$dest = imagecreatetruecolor($width, $height);
		
		/* copy old image to the new image and resize it */
		imagecopyresized($dest, $source, 0,0,0,0,$width,$height,$oldwidth,$oldheight);
		
		/* if a string exists then brand the picture with it */
		if ($string != '') {
			imagestring($dest, 5, 0, 0, $string, imagecolorallocate($dest,255,255,255)); 
		}
		
		/* Return resized image */
		return $dest;
}

/* ptlib's scandir */
function ptlib_scandir($directory){
   $folderContents = array();
   $directory = realpath($directory).DIRECTORY_SEPARATOR;
   foreach (ptlib_scandirphp4($directory) as $folderItem) {
       if ($folderItem != "." AND $folderItem != "..") {
           if (is_dir($directory.$folderItem.DIRECTORY_SEPARATOR)) {
               $folderContents['folders'][] = $folderItem;
           }
           else {
               if ($folderItem != "Thumbs.db") {
					$folderContents['files'][] = $folderItem;
				}
           }
       }
   }
   return $folderContents;
}

/* PHP 4 Does not have support for scandir() */
function ptlib_scandirphp4($directory) {
	$dh  = opendir($directory);
	while (false !== ($filename = readdir($dh))) {
	   $files[] = $filename;
	}
	return $files;
}

/* Images only... This was a quick hack for the folder thumbnail preview */
function ptlib_scanimages($directory){
	$contents = ptlib_scandir($directory);
	$scan = array();
	if (count($contents['files']) == 0) { return array(); }
	foreach ($contents['files'] as $item) {
		if (stripos($item,'.jpg') or stripos($item,'.jpeg') or stripos($item,'.gif') or stripos($item,'.png') ) {
			$scan[] = $item;
		}
	
	}
	return $scan;
}

function thumb_index() {
	global $thumb_dir, $big_dir;

	/* Define the styles */
	echo "<style></style>";
	echo "<style></style>";

	$contents = ptlib_scandir($GLOBALS['folder']);
	$GLOBALS['folders'] = substr($GLOBALS['folder'],strlen($GLOBALS['base_dir']));	
	
	if ($GLOBALS['folder'] != $GLOBALS['base_dir']) {
		echo "<div class=\"folder\"><a href=\"?folder=" . urlencode($GLOBALS['folders'] . "/../") ."\"><img style=\"border:0px\" src=\"?folder=" . urlencode($GLOBALS['folders'] . "/../") . "&view=folder\" /></a><pre style=\"text-align: center; margin:0px;\">../</pre></div>";
	}
	
	if (count(@$contents['folders']) > 0) {
		foreach ($contents['folders'] as $item) {
			if ($item != $thumb_dir && $item != $big_dir){  
			if (strlen($item) > 13) {
				$items = substr($item,0,10).'...';
			} else {
				$items = $item;
			}
			echo "<div class=\"folder\"><a href=\"?folder=".urlencode($GLOBALS['folders'] ."/". $item)."\"><img style=\"border:0px\" src=\"?folder=" .urlencode($GLOBALS['folders'].'/'.$item) . "&view=folder\" /></a><pre style=\"text-align: center; margin:0px;\">$items</pre></div>";
			}
		}
	}

	echo "<br style=\"clear:both;\">";
	if (count($contents['files']) > 0) {
		foreach ($contents['files'] as $item) {
			if (stripos($item,'.jpg') or stripos($item,'.jpeg') or stripos($item,'.gif') or stripos($item,'.png') ) {
			if (strlen($item) > 13) {
				$items = substr($item,0,10).'...';
			} else {
				$items = $item;
			}
				echo "<div class=\"file\"><center><a href=\"?folder=" . urlencode($GLOBALS['folders']) . "&view=bigpage&file=" . urlencode($item) . "\"><img style=\"border:0px;\" src=\"?view=thumb&file=" . urlencode($item) . "&folder=" . urlencode($GLOBALS['folders']) . "\" /></a><pre style=\"text-align: center; margin:0px;\">$items</pre><center></div>";
			}
		}
	}

	echo "<br style=\"clear:both;\"><center style=\"font-family:arial;\"><a href=\"http://webjo.no-ip.org\">webjo - web-journal</a></center>";
	
}

function thumb_pic() {
	global $file, $folder, $big_dir, $thumb_dir;
	
	$myfile=$folder .'/'.$file;

	function getimage($file) {
		$ext = getimagesize($file);
		
		switch ($ext[2]) {
			case 2:
				return @imagecreatefromjpeg($file);
				break;
			case 1:
				return @imagecreatefromgif($file);
				break;
			case 3:
				return @imagecreatefrompng($file);
				break;
			default:
				return false;
		}
	
	}
	
	switch ($_GET['view']) {
		case 'bigpage':
				echo "<style></style>";
				echo "<div class=\"file\" style=\"padding-top:0px;margin:0px;\"><a href=\"?folder={$_GET['folder']}\">back</a><br /><img src=\"?folder={$_GET['folder']}&file={$_GET['file']}&view=big\" /></div>";
				break;
		case 'big':
			/* Check for cached */
			header('content-type: image/jpeg');

			if (file_exists($folder.'/'.$big_dir.'/'.$file)) {
				echo readfile($folder.'/'.$big_dir.'/'.$file);
				exit;
			}
			
			$source = getimage($myfile);
			
			$source = resize_image($source, $GLOBALS['big_width'], $GLOBALS['big_height']);
			if ($GLOBALS['cache'] == true) {
				if (!file_exists($folder.'/'.$big_dir)) {
					@mkdir ($folder.'/'.$big_dir);
				}
				if (file_exists($folder.'/'.$big_dir)) {
					imagejpeg($source, $folder.'/'.$big_dir.'/'.$file, $GLOBALS['qaulity']);
				}
			}
			imagejpeg($source, '', $GLOBALS['qaulity']);
			
			
			
			break;
		case 'full':
		header('content-type: image/jpeg');			
		if (file_exists($folder.'/'.$file)) {
				echo file_get_contents( $folder.'/'.$file );
				exit;
			}
			break; 
		case 'thumb':
		header('content-type: image/jpeg');			

		if (file_exists($folder.'/'.$thumb_dir.'/'.$file)) {
				echo file_get_contents($folder.'/'.$thumb_dir.'/'.$file);
				exit;
			}
			$source = getimage($myfile);
			$source = resize_image($source, $GLOBALS['thumb_width'], $GLOBALS['thumb_height']);
			
			if ($GLOBALS['cache'] == true) {
				if (!file_exists($folder.'/'.$thumb_dir)) {
					@mkdir ($folder.'/'.$thumb_dir);
				}
				if (file_exists($folder.'/'.$thumb_dir)) {
					imagejpeg($source, $folder.'/'.$thumb_dir.'/'.$file, $GLOBALS['qaulity']);
				}
			}
			imagejpeg($source, '', $GLOBALS['qaulity']);
			break;
		case 'folder':
		header('content-type: image/jpeg');
		if (file_exists($folder.'/'.$thumb_dir.'/__FOLDER.JPG')) {
			echo readfile($folder.'/'.$thumb_dir.'/__FOLDER.JPG');
			exit();
		}
		$contents=ptlib_scanimages($folder);
			switch (count($contents)) {
				case 0:
					$height = ($GLOBALS['thumb_width'])/1.33; /* make sure all folders look the same */
					$dest = imagecreatetruecolor(5,8); //$GLOBALS['thumb_width'], $height);
					imagefill($dest,1,1,imagecolorallocate($dest,255,255,255));
					imagestring($dest,1,0,0,"?", imagecolorallocate($dest, 0,0,0));
					imagejpeg( resize_image ($dest,120,90));
					
					exit();
				case 1:
					$source = getimage($folder.'/'.$contents[0]);
					$source = resize_image($source, $GLOBALS['thumb_width'], $GLOBALS['thumb_height']);
					imagejpeg($source,'',$GLOBALS['qaulity']);
					exit();
				case 2:
				case 3:
					$source1 = getimage($folder.'/'.$contents[0]);
					$source2 = getimage($folder.'/'.$contents[1]);
					$source4 = getimage($folder.'/'.$contents[0]);
					$source3 = getimage($folder.'/'.$contents[1]);

					break;
				default:
					$source1 = getimage($folder.'/'.$contents[0]);
					$source2 = getimage($folder.'/'.$contents[1]);
					$source3 = getimage($folder.'/'.$contents[2]);
					$source4 = getimage($folder.'/'.$contents[3]);
					break;
			}

					$height = ($GLOBALS['thumb_width'])/1.33; /* make sure all folders look the same */
					
					$source1 = resize_image($source1, ($GLOBALS['thumb_width'])/2,$height/2);
					$source2 = resize_image($source2, ($GLOBALS['thumb_width'])/2,$height/2);
					$source3 = resize_image($source3, ($GLOBALS['thumb_width'])/2,$height/2);
					$source4 = resize_image($source4, ($GLOBALS['thumb_width'])/2,$height/2);
					
					
					$dest = imagecreatetruecolor($GLOBALS['thumb_width'], $height);
					/*                                                DEST            SOURCE     dest X                                                           y   x   y   w   h   */
					imagecopyresized($dest, $source1,                        0,0,0,0,@imagesx($source1),@imagesy($source1),@imagesx($source1),@imagesy($source1));
					imagecopyresized($dest, $source2,$GLOBALS['thumb_width']/2,0,0,0,@imagesx($source2),@imagesy($source2),@imagesx($source2),@imagesy($source2));					
					imagecopyresized($dest, $source3,                        0,$height/2,0,0,@imagesx($source3),@imagesy($source3),@imagesx($source3),@imagesy($source3));
					imagecopyresized($dest, $source4,$GLOBALS['thumb_width']/2,$height/2,0,0,@imagesx($source4),@imagesy($source4),@imagesx($source4),@imagesy($source4));					
					
					if ($GLOBALS['cache'] == true) {
						if (!file_exists($folder .'/'.$thumb_dir."/")) {
							@mkdir ($folder .'/'.$thumb_dir."/");
						}
						if (file_exists($folder .'/'.$thumb_dir."/")) {
							imagejpeg($dest,$folder .'/'.$thumb_dir.'/__FOLDER.JPG', $GLOBALS['qaulity'] );
						}
					}
					imagejpeg($dest,'',$GLOBALS['qaulity']);
			break;
		}
	}
	
if (@$_GET['view'] == 'folder') {
	thumb_pic();
	exit;
}

switch (isset($_GET['file'])) {
	case false:
		echo "";
		thumb_index();
		break;
	case true:
		thumb_pic();
		break;
}


?>
 
Нещо простичко:
Код:
<?php
function getFiles($path) {
$files = array();
$fileNames = array();
$i = 0;
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if ($file == "." || $file == "..") continue;
$fullpath = $path . $file;
$fkey = strtolower($file);
$file_type = strtolower(end(explode(".",$fkey)));
if($file_type != 'jpg' && $file_type != 'gif' && $file_type != 'png') continue;
$files[$fkey]['type'] = $file_type;
while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
$a = stat($fullpath);
$files[$fkey]['size'] = $a['size'];
if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
$files[$fkey]['name'] = $file;

$fileNames[$i++] = $fkey;
}
closedir($dh);
} else die ("Cannot open directory: $path");
} else die ("Path is not a directory: $path");
sort($fileNames,SORT_STRING);
$sortedFiles = array();
$i = 0;
foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
return $sortedFiles;
}
$files = getFiles("./");

foreach ($files as $file)

print "<b><a href=\"$file[name]\"><img src=\"$file[name]\" >$file[name]</a></b><br>\n";
?>
 
Благодаря, но на мен ми трябва скрипт за картинките като този на http://forumi.bg/rangove.php .
 
Аз немога да го преправя да ти върши точно същата работа, но ако всички рангове са в 1 папка и им попромениш малко имената ще се получи това: http://89.190.212.246/dir/ а ето го и кода:
Код:
<?php
function getFiles($path) {
$files = array();
$fileNames = array();
$i = 0;
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if ($file == "." || $file == "..") continue;
$fullpath = $path . $file;
$fkey = strtolower($file);
$file_type = strtolower(end(explode(".",$fkey)));
if($file_type != 'jpg' && $file_type != 'gif' && $file_type != 'png') continue;
$files[$fkey]['type'] = $file_type;
while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
$a = stat($fullpath);
$files[$fkey]['size'] = $a['size'];
if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
$files[$fkey]['name'] = $file;

$fileNames[$i++] = $fkey;
}
closedir($dh);
} else die ("Cannot open directory: $path");
} else die ("Path is not a directory: $path");
sort($fileNames,SORT_STRING);
$sortedFiles = array();
$i = 0;
foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
return $sortedFiles;
}
$files = getFiles("./");

foreach ($files as $file)

print "
<table border=\"0\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\">
	<tr>
		<td><img src=\"$file[name]\" border=\"0\" ></td>
		<td>   </td>
		<td>$file[name]</td>
	</tr>
</table>
";
?>
 
sniperbg каза:
Благодаря, но на мен ми трябва скрипт за картинките като този на http://forumi.bg/rangove.php .
И на мен ми трябва това "jooorooo" ти можеш ли да го направиш по начинът по който е направено в http://forumi.bg/rangove.php или ако не ти "jooorooo" някой друг.Защото варианта на porostorm е доста неудобен защото трябва да се променят имената на повече от 300 изображения.
 
princo каза:
Защото варианта на porostorm е доста неудобен защото трябва да се променят имената на повече от 300 изображения.
Вариантът на porostorm може да се промени от някой с 1 ред и да върши същата работа като примера :)
 
porostorm каза:
princo каза:
Защото варианта на porostorm е доста неудобен защото трябва да се променят имената на повече от 300 изображения.
Вариантът на porostorm може да се промени от някой с 1 ред и да върши същата работа като примера :)
Добре де този някой може ли да промени 1 ред защото ми е много важно и нужно ще съм много благодарен
 

Back
Горе