---
title: "bild"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/81223-bild"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "badmongo"
published: "2003-07-03T14:37:42.000Z"
updated: "2003-07-04T20:34:19.000Z"
replies: 1
views: 304
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/81223-bild"
---

# bild

## #1 — badmongo, 2003-07-03T14:37Z

hej. jag har ett script som lisatr  upp alla filer (bilder i en mapp)

nu skulle jag gärna vilja att den visar  bara en bild sen så är  det en \[nästa\] knapp till nästa bild och en  \[förra\] knapp till föregående bild.  går detta att fixa ???

/ ERIK

\-------------------listafiler.php------------------------------
\<?php
		
		
		function Cache() 
{ 
header("Pragma: no-cache"); 
header("Cache-control: no-cache"); 
}
		
		
$filedir = "filer";
$dh = opendir($filedir);
while(gettype($file = readdir($dh)) != boolean)
{
if (is_dir("$filedir/$file")) {
} else {

$size = getimagesize("$filedir/$file");
$info = pathinfo("$file");

echo "\<img src='$filedir/$file' width='$size\[0\]' height='$size\[1\]' border='0'\>\<br\>";

}
}
closedir($dh);
?\>

\--------------------------listafiler.php------------------------------

Permalänk: https://www.webforum.nu/p/81223

## #2 — Matte, 2003-07-04T20:34Z

Vet inte om du lyckats lösa det, annars borde det gå att göra något liknande detta:

```php
$images = array();

$filedir = "filer"; 
$dh = opendir($filedir); 
while(gettype($file = readdir($dh)) != 'boolean') 
{ 
   if ($file != "." && $file != ".." && !is_dir("$filedir/$file")) { 
      $images[] = "$filedir/$file";
   } 
}
closedir($dh); 

$antal_bilder = sizeof($images);

if (isset($_GET['image']) && $_GET['image'] > 0 
          && $_GET['image'] <= $antal_bilder) {
   $image = $_GET['image'];
} else $image = 1;

if ($antal_bilder > 0) {

   $size = getimagesize($images[$image-1]); 
   echo "<img src='{$images[$image-1]}' $size[3] border='0'><br>"; 
   
   if ($image > 1) {
     echo "<a href=\"listafiler.php?image=".($image-1)."\">Förra</a>\n";
   }
   
   if ($image < $antal_bilder) {
     echo "<a href=\"listafiler.php?image=".($image+1)."\">Nästa</a>\n";
   }

}
```

Permalänk: https://www.webforum.nu/p/1101050

---

Tråden på webben: https://www.webforum.nu/amne/php/81223-bild
