22. maj 2002 - 03:51Der er
4 kommentarer og 1 løsning
Image-viewer viser alle filer :-(
Jeg har gang i et image-viewer-script... Jeg har forsøgt at få det til kun at vise jpg, png og gif billeder, men den forsøger alligevel at vise zip og alle andre filer... Hvorledes skal koden se ud for at det virker korrekt?
her er min kode nu:
image_viewer.php3 --------------------- <HTML> <BODY> <? $dirname = "files"; $img_directory = opendir($dirname); while($img = readdir($img_directory)) { $images[] = $img; } closedir($img_directory); $size = count($images); if ($sp > 0) { $image = $images[$sp]; if ($image == "") { print("You have reached the end of the images in this directory."); print("</BODY></HTML>"); exit; } elseif ($image == "..") { $sp++; $image = $images[$sp]; } elseif ($image == "image_viewer.php3") { $sp++; $image = $images[$sp]; if ($image == "") { print("You have reached the end of the images in this directory."); print("</BODY></HTML>"); exit; } } } else { $break = explode(".", $image); if(($break[1] == "gif") OR ($break[1] == "jpg") OR ($break[1] == "png")) { $image = $images[0]; if ($image == ".") { $image = $images[1]; $sp=1; } if ($image == "..") { $image = $images[2]; $sp=2;} } } print("<br>I am displaying picture file: <strong>$image</strong><br>"); $sp++; ?> <form method="post" action="image_viewer.php3"> <input type="hidden" name="sp" value="<?print($sp);?>"> <input type="submit" value="Display Next Picture"> <?php print("<br><img src=\"$dirname/$image\">"); ?> </form> </BODY> </HTML>
jeg har fundet et script, hvor den viser alle billeder i en mappe på serveren!!! Den laver selv THUMPNAILS :O) smart, og let at sætte op!! Vil du have det??
//Image path $libery="billeder/"; // remember to finish with /
// Settings Stop----------//
$viewNum=$cols*$rows; if(!$firstImage){ // so it works if you just enter default.php and show the pictures without having to define the variables in the path $firstImage=1; } function getImages($firstImage){ global $viewNum, $imageWidth, $imageHeight,$cols,$libery; //insures that the function gets the variables $handle=opendir($libery); //opens directory while($file=readdir($handle)){ // reads the directory $extension=substr($file,-4); // gets the extension of the files if(($extension == ".jpg") || ($extension == ".gif") || ($extension == ".png") ){ // checks for image files $all[]=$file; //adds positive results to the archive } } $colscounter=0; // variable that controls the tablebuilding system below $firstImage--; // variable that insures that the first image is being showed. Case: It looks best if the links begins with 1 but the array begins with 0 if(isset($all)){ // if array is set build the table print "<table>"; for($i=$firstImage; $i < $firstImage+$viewNum; $i++){ if($all[$i]){ // checks for rinning dry of imges if($i==$firstImage + $colscounter*$cols){ // if true: new row $colscounter++; print "<tr>"; } // add the image print "<td><a href='".$libery."".$all[$i]."'><img src='".$libery."".$all[$i]."' border='0' width='$imageWidth' height='$imageHeight' alt='Klik på billedet for at se det i stort!'></a></td>"; } else{ // stop if no more images break; } } print "</table><br>"; makeList($num); // function to make the links list } else{ print "Der var desværre ingen billeder i dette bibliotek<br><a href='java script:history.back()'>Tilbage</a>"; } } function makeList($num){ global $libery, $firstImage, $viewNum; //insures that the function gets the variables $numLinks = $num / $viewNum; // finds the number og links to be maked for($a=0; $a < $numLinks;$a++){ $start=$a*$viewNum+1; //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20 $finish=$a*$viewNum+$viewNum; if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much $finish=$num; } if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page print "$start - $finish</a> "; } else{ // makes the link print "<a href='billeder.php?libery=$libery&firstImage=$start'>$start - $finish</a> "; } } } ?>
billeder.php
<? include("functions.inc"); ?>
<? getImages($firstImage); ?>
---------------------------
Sådan.. håber du kan bruge det... det er som sagt ikke mig der har lavet det, men det er yderst effektivt!
Det er bare perfekt! MEGET bedere end det jeg havde gang i :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.