ugrás a tartalomhoz

PHP - opendir()

Lupesz · 2010. Már. 27. (Szo), 23.33
Sziasztok!
Kreáltam egy kis galériás srciptet, amivel van egy kis gond! Bár téma nyitás előtt végig olvastam a témakörhöz kapcsolódó bejegyzéseket, de sajna nem jöttem rá nálam mi a para...
Szóval íme a problémám:
A kód annyit csinál h kikeresi az index.php fájlal egy mappában lévő képeket, amikhez készít thumbnail-t majd azokat megjeleníti, es a th-ra kattintva meg lehet nyitni a képet eredeti méretében. A gond viszont az, hogy az opendir-t így használom: opendir('.') igy természetesen remekül fut, listázza az index.php-val egy mappában lévő képeket. Azonban mikor azt szeretném, hogy az index mellett lévő images mappát listázza nem tesz semmit.
Íme a kód:
<?php

$columns     = 5;
$thmb_width  = 120;
$thmb_height = 80;

function resizeImage($originalImage,$toWidth,$toHeight){
   
    list($width, $height) = getimagesize($originalImage);
    $xscale=$width/$toWidth;
    $yscale=$height/$toHeight;
   
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefromjpeg ($originalImage);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0,
                       $new_width, $new_height, $width, $height);

    return $imageResized;
}

function generateThumbnails(){
    global $thmb_width,$thmb_height;

    if ($handle = @opendir('.')) {
        while ($file = readdir($handle))  {
            if (is_file($file)){
                  if (strpos($file,'_th.jpg')){
                      $isThumb = true;
                  } else {
                      $isThumb = false;
                  }
             
                  if (!$isThumb) {
                      $dirName  = substr($file,0,strpos($file,basename($file)));
                      if (strlen($dirName) < 1) $dirName = '.';
                      $fileName = basename($file);
                      $fileMain = substr($fileName,0,strrpos($fileName,'.'));
                      $extName  = substr($fileName,strrpos($fileName,'.'),
                                          strlen($fileName)-strrpos($fileName,'.'));
                     
                      if (($extName == '.jpg') || ($extName == '.jpeg')){
                        $thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
                        if (!file_exists($thmbFile)){
                            imagejpeg(resizeImage($file,$thmb_width,$thmb_height)
                                     ,$thmbFile,80);
                        }
                    }
                  }
               }
           }
    }
   
}

function getNormalImage($file){
    $base = substr($file,0,strrpos($file,'_th.jpg'));
    if (file_exists($base.'.jpg')) return $base.'.jpg';
    elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
    else return "";
}

function displayPhotos(){
    global $columns;
   
    generateThumbnails();
    $act = 0;
    if ($handle = @opendir('.')) {
        while ($file = readdir($handle))  {
            if (is_file($file)){
                  if (strpos($file,'_th.jpg')){
                    ++$act;
                    if ($act > $columns) {
                        echo '</tr><tr>
                           <td class="photo"><a href="'.getNormalImage($file).'">
                               <img src="'.$file.'" alt="'.$file.'"/></a></td>';  
                        $act = 1;
                    } else {
                        echo '<td class="photo"><a href="'.getNormalImage($file).'">
                           <img src="'.$file.'" alt="'.$file.'"/></a></td>';  
                    }
                     
                  }
              }
        }
    }  
}

?>

<html>
<head>
   <title>Photo Gallery</title>
</head>
<body>
  <center><h3>Photo Gallery</h3></center>
  <table align="center"><tr>    
    <?php displayPhotos(); ?>
  </table>      
</body>  


</html>


Esetleg valaki tudna segíteni, hogy mi lehet a probléma?
 
1

images mappa

ironwill · 2010. Már. 28. (V), 00.10
Szia!

Ha az images mappát akarod, akkor az "##kukac##opendir('.')" helyett használd a "@opendir('images')"-t.

üdv, Gábor
2

Szia! Próbáltam úgy is...de

Lupesz · 2010. Már. 28. (V), 00.23
Szia!

Próbáltam úgy is...de valamiért nem jön össze :(
Azóta már kicsit módosítottam rajta, bevezettem egy $dir változót és igy ez lett:
$dir='../images';
@opendir($dir)
Valamit az egészet egy feltételbe tettem így:
if (is_dir($dir))
{....}
else
{echo "nem könyvtár";}
Ennek pedig az lett az eredménye, hogy "nem könyvtár"....
Próbáltam teljes elérési útvonal megadásával is, de az sem nyert...
Esetleg valami ötlet ehhez? :)
3

__FILE__

oszi330 · 2010. Már. 28. (V), 10.03
Szia!

próbáld így:
  1. opendir(dirname(__FILE__)."/images")  
4

Sziasztok! Végül csak

Lupesz · 2010. Már. 28. (V), 14.53
Sziasztok!
Végül csak sikerült megoldani a problémám. Köszi a segítséget.
Íme a teljes kód ha esetleg érdekel valakit:
  1. <?php  
  2.   
  3. $columns     = 5;  
  4. $thmb_width  = 120;  
  5. $thmb_height = 80;  
  6.   
  7. function resizeImage($originalImage,$toWidth,$toHeight){  
  8.      
  9.     list($width$height) = getimagesize($originalImage);  
  10.     $xscale=$width/$toWidth;  
  11.     $yscale=$height/$toHeight;  
  12.      
  13.     if ($yscale>$xscale){  
  14.         $new_width = round($width * (1/$yscale));  
  15.         $new_height = round($height * (1/$yscale));  
  16.     }  
  17.     else {  
  18.         $new_width = round($width * (1/$xscale));  
  19.         $new_height = round($height * (1/$xscale));  
  20.     }  
  21.     $imageResized = imagecreatetruecolor($new_width$new_height);  
  22.     $imageTmp     = imagecreatefromjpeg ($originalImage);  
  23.     imagecopyresampled($imageResized$imageTmp, 0, 0, 0, 0,  
  24.                        $new_width$new_height$width$height);  
  25.   
  26.     return $imageResized;  
  27. }  
  28.   
  29. function generateThumbnails(){  
  30.     global $thmb_width,$thmb_height;  
  31. $dir = "./images";  
  32.   
  33. if (is_dir($dir))  
  34. {  
  35.     if ($handle = @opendir($dir)) {  
  36.         while ($file = readdir($handle))  {  
  37. $file = $dir."/".$file;  
  38.             if (is_file($file)){  
  39.                   if (strpos($file,'_th.jpg')){  
  40.                       $isThumb = true;  
  41.                   } else {  
  42.                       $isThumb = false;  
  43.                   }  
  44.                
  45.                   if (!$isThumb) {  
  46.                       $dirName  = substr($file,0,strpos($file,basename($file)));  
  47.                       if (strlen($dirName) < 1) $dirName = '.';  
  48.                       $fileName = basename($file);  
  49.                       $fileMain = substr($fileName,0,strrpos($fileName,'.'));  
  50.                       $extName  = substr($fileName,strrpos($fileName,'.'),  
  51.                                           strlen($fileName)-strrpos($fileName,'.'));  
  52.                        
  53.                       if (($extName == '.jpg') || ($extName == '.jpeg')){  
  54.                         $thmbFile = $dirName.'/'.$fileMain.'_th.jpg';  
  55.                         if (!file_exists($thmbFile)){  
  56.                             imagejpeg(resizeImage($file,$thmb_width,$thmb_height)  
  57.                                      ,$thmbFile,80);  
  58.                         }  
  59.                     }  
  60.                   }  
  61.                }  
  62.            }  
  63.     }  
  64.      
  65. }  
  66. else  
  67. {  
  68. echo "nem konyvtar";  
  69. }  
  70. }  
  71.   
  72.   
  73. function getNormalImage($file){  
  74.     $base = substr($file,0,strrpos($file,'_th.jpg'));  
  75.     if (file_exists($base.'.jpg')) return $base.'.jpg';  
  76.     elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';  
  77.     else return "";  
  78. }  
  79.   
  80. function displayPhotos(){  
  81.     global $columns;  
  82.     $dir = "./images";  
  83.     generateThumbnails();  
  84.     $act = 0;  
  85.   
  86. if (is_dir($dir))  
  87. {  
  88.     if ($handle = @opendir($dir)) {  
  89.         while ($file = readdir($handle))  {  
  90. $file = $dir."/".$file;  
  91.             if (is_file($file)){  
  92.                   if (strpos($file,'_th.jpg')){  
  93.                     ++$act;  
  94.                     if ($act > $columns) {  
  95.                         echo '</tr><tr>  
  96.                            <td class="photo"><a href="'.getNormalImage($file).'">  
  97.                                <img src="'.$file.'" alt="'.$file.'"/></a></td>';     
  98.                         $act = 1;  
  99.                     } else {  
  100.                         echo '<td class="photo"><a href="'.getNormalImage($file).'">  
  101.                            <img src="'.$file.'" alt="'.$file.'"/></a></td>';     
  102.                     }  
  103.                        
  104.                   }  
  105.               }  
  106.         }  
  107.     }     
  108. }  
  109.   
  110. else  
  111. {  
  112. echo "nem könyvtar";  
  113. }  
  114. }  
  115. ?>  
  116.   
  117. <html>  
  118. <head>  
  119.    <title>Photo Gallery</title>  
  120. </head>  
  121. <body>  
  122.   <center><h3>Photo Gallery</h3></center>  
  123.   <table align="center"><tr>       
  124.     <?php displayPhotos(); ?>  
  125.   </table>         
  126. </body>     
  127.   
  128.   
  129. </html>  
5

Sziasztok! Nekem is ez a bajom...

kranyo · 2011. Szep. 2. (P), 11.50
Sziasztok!

Nekem is az a bajom, hogy ha az index.php-vel azonos könyvtárból nyitom meg a mappákat akkor működik a galéria. De ha változtatok, és létrehozok egy mappát ami tartalmazni fogja a többi, képeket tartalmazó mappát, nem működik. Próbáltam a $dir = "./gal"; így is teljes útvonallal is...

Köszönöm!

config.php:
  1. <?php  
  2.   
  3. //Slide gallery variables  
  4. $place = "."//directory of the slide mount images, no need to change  
  5. $col = 3; //no. of columns in a page  
  6. $maxrow = 2; //no. of rows in a page  
  7. //$dir="."; //directory for this script, no need to change  
  8. $dir = "./gal";  
  9. $thumb = true ; //setting it to TRUE will generate real thumbnails on-the-fly, supports jpg file only and requires GD library. Setting it to FALSE will resize the original file to fit the thumbnail size, long download time. Turn it off if thumbnails don't show properly.  
  10. $croptofit = true ; //TRUE will crop the thumbnail to fit the aspect ratio of the slide mount if they aren't the same. False won't crop the thumbnail but it will be distorted if both aspect ratios are not the same.  
  11. $rollover = true ;  //thumbnail rollover effect for IE only  
  12.   
  13. //Upload/Delete Module variables  
  14. $LOGIN = "admin";  
  15. $PASSWORD = "admin";  
  16. $abpath = "./gal"//Absolute path to where images are uploaded. No trailing slash  
  17. $sizelim = "no"//Size limit, yes or no  
  18. $size = "2500000"//Size limit if there is one  
  19. $number_of_uploads = 5;  //Maximum number of uploads in one time  
  20.   
  21. ?>  
index.php:
  1. <?php  
  2. $imgdir = $_GET['imgdir'] ;   
  3. $page = $_GET['page'];  
  4. $a_img = array();  
  5.   
  6. include("header.inc");  
  7. require('config.php');  
  8.   
  9. if ($rollover)  
  10. {  
  11. include('rollover.txt');  
  12. }  
  13. ///// for captioning  
  14. function caption($filename) {  
  15.    $is_captioned = check_perms($filename);  
  16.     if ($is_captioned) {  
  17. print"<br><font face='Arial, Helvetica, sans-serif' size=2 color='#999999'>";  
  18.       include($filename);  
  19. print"</font>";  
  20.     }  
  21. }  
  22. ///// for album description  
  23. function album($filename) {  
  24.    $is_captioned = check_perms($filename);  
  25.     if ($is_captioned) {  
  26. print"<font face='Arial, Helvetica, sans-serif' size=3 color='#cccccc'>";  
  27.       include($filename);  
  28. print"</font><br>";  
  29.     }  
  30. }  
  31.   
  32. ////check file permission  
  33. function check_perms($filename) {  
  34.       
  35. if (! file_exists($filename)) return false;  
  36.       
  37.   $fileperms = fileperms($filename);  
  38.   $isreadable = $fileperms & 4;  
  39.   if ( is_file($filename) ) {  
  40.     // pictures, thumbnails, config files and comments only need to be readable  
  41.     if (! $isreadable) {  
  42.       if (MODE_WARNING) print "$filename: wrong permission <br>";  
  43.     }  
  44.     return $isreadable;   
  45.   }  
  46.   else if ( is_dir($filename) ) {  
  47.     // galleries need to be both readable and executable  
  48.     $isexecutable = $fileperms & 1;  
  49.     if (! $isreadable || ! $isexecutable)  
  50.       if (MODE_WARNING) print "$filename: wrong permission <br>";  
  51.     return ( $isreadable && $isexecutable); // ($dirperms & 5) == 5 ?  
  52.   }  
  53.     
  54.   // default behavior: the filename does not exist  
  55.   return false;  
  56. }  
  57.   
  58. //$dir = "./gal";  
  59.   
  60. $dh = @opendir($dir);  
  61.    
  62.   
  63.   
  64.   
  65.  while($file = readdir($dh))  
  66.  {  
  67. if ($file != "." && $file != ".."&& is_dir($file))     
  68. {$dname[] = $file;  
  69. sort($dname);  
  70. reset ($dname);  
  71.  }  
  72. }  
  73.   
  74.   
  75. print "<script language=\"JavaScript\">";  
  76. print "function MM_jumpMenu(targ,selObj,restore){eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");";  
  77. print "  if (restore) selObj.selectedIndex=0;}";  
  78. print "</script>";  
  79.   
  80. //print "<select name=\"menu1\" onChange=\"MM_jumpMenu('parent',this,0)\">";  
  81. //print "<option value=\"#\">Képek...</option><br>\n";  
  82. $u=0;  
  83. print"<table>";  
  84.  foreach($dname as $key=>$val)  
  85.   {    
  86.     
  87.     
  88.   if($dname[$u])     
  89.     {   
  90.         if(($u%5)==0)  
  91.         {  
  92.             print"<tr>";  
  93.         }  
  94.         print"<td><a href=\"index.php?imgdir=$dname[$u]\">$dname[$u]</a></td>";  
  95.         //print "<option value=\"index.php?imgdir=$dname[$u]\">$dname[$u]</option>\n";  
  96. $u++;  
  97.     }  
  98.   }  
  99.   
  100. print"</table>";  
  101.   
  102. if ($imgdir =="")  
  103. {$imgdir = $dname[0];  
  104. }  
  105.   
  106. print $imgdir;  
  107. $dimg = opendir($imgdir);  
  108. print $dimg;  
  109.  while($imgfile = readdir($dimg))  
  110.  {  
  111.  if( (substr($imgfile,-3)=="gif") || (substr($imgfile,-3)=="jpg")  || (substr($imgfile,-3)=="JPG") || (substr($imgfile,-3)=="GIF")  )  
  112.  {  
  113.    $a_img[count($a_img)] = $imgfile;  
  114. sort($a_img);  
  115. reset ($a_img);  
  116.  }   
  117. }  
  118. //print $a_img[1];  
  119.   
  120. print "<h2>$imgdir</h2>";  
  121.   
  122.  $totimg = count($a_img); // total images number  
  123.  $totxpage = $col*$maxrow// images x page  
  124.  $totpages = ($totimg%$totxpage==0)?((int)$totimg/$totxpage):((int)($totimg/$totxpage)+1); // number of total pages  
  125.   
  126.  if($totimg == false)  
  127.    print "<br><font size=2 face=verdana>No Images available in your \"IMAGES\" directory yet!!</font><br>";  
  128.  else  
  129.  {  
  130.   
  131. ///print album description  
  132. $album_name = "$imgdir/album.txt";  
  133. album($album_name);  
  134.   
  135. print "<center> <div id='gallery'><table width=700 bgcolor=#474747 border=0 bordercolor=#ffffff cellpadding=2 cellspacing=3>\n";  
  136.   // start page  
  137.   if($page=="" || $page==1)  
  138.   {  
  139.    $x=0;  
  140.    $page = 1;  
  141.   }  
  142.   else  
  143.    $x = (($page-1)*($totxpage));  
  144.   $r=0;  
  145.   
  146.   // print of table  
  147.   foreach($a_img as $key=>$val)  
  148.   {  
  149. $caption_name = "$imgdir/$a_img[$x].txt";  
  150.   
  151.    if(($x%$col)==0)  
  152.     print "<tr>\n";  
  153.    if($a_img[$x])  
  154.    {  
  155. $size = getimagesize ("$imgdir/$a_img[$x]");  
  156. $halfw = round($size[0]/2);  
  157. $halfh = round($size[1]/2);  
  158. $quarterw = round($size[0]/4);  
  159. $quarterh = round($size[1]/4);  
  160. if($size[1] < $size[0])  
  161. {  
  162.     $height = 86;  
  163.     $width = 130;  
  164.     $imgnumber = ($x+1);  
  165.     if("$imgdir/$a_img[$x]" !="")  
  166.   
  167. if ($thumb){  
  168. $thumbnail = "thumbs.php?image=$imgdir/$a_img[$x]&newheight=86&newwidth=130&width=$size[0]&height=$size[1]";  
  169. }  
  170. else   
  171. {  
  172. $thumbnail =  "$imgdir/$a_img[$x]";  
  173. }  
  174. $kep=  "$imgdir/$a_img[$x]";  
  175. print "<td align=center valign=top>";  
  176. print "<TABLE WIDTH=198 BORDER=0 CELLPADDING=0 CELLSPACING=0>";  
  177. print "<TR><TD COLSPAN=3><IMG SRC=\"$place/slide_01.gif\" WIDTH=198 HEIGHT=47></TD></TR>";  
  178. print "<TR><TD><IMG SRC=\"$place/slide_02.gif\" WIDTH=33 HEIGHT=86></TD>";  
  179.   
  180.   
  181. echo '<td><a href="', urlencode($imgdir), '/', urlencode($a_img[$x]),'">';  
  182.   
  183.   
  184.   
  185. //echo '<TD><a href="',rawurlencode($kep), '">';  
  186.   
  187. print"<img src=\"$thumbnail\" height=$height width=$width border=0 alt='$a_img[$x]' style=\"filter:alpha(opacity=100)\" onmouseout=\"gradualfade(this,100,30,4)\" onmouseover=\"gradualfade(this,40,50,100)\"></a></TD>";  
  188. print "<TD><IMG SRC=\"$place/slide_04.gif\" WIDTH=35 HEIGHT=86></TD></TR><TR>";  
  189. print "<TD COLSPAN=3><IMG SRC=\"$place/slide_05.gif\" WIDTH=198 HEIGHT=56><br><font size=\"1\">";  
  190. caption($caption_name);  
  191. print "</TD></TR>";  
  192. print "</TABLE></center>";  
  193. print "</td>\n";  
  194. }  
  195. else  
  196. {    $height = 130;  
  197.     $width = 86;  
  198. if ($thumb){  
  199. $thumbnail = "thumbs.php?image=$imgdir/$a_img[$x]&newheight=130&newwidth=86&width=$size[0]&height=$size[1]";  
  200. }  
  201. else   
  202. {  
  203. $thumbnail =  "$imgdir/$a_img[$x]";  
  204. }  
  205.  $imgnumber = ($x+1);  
  206.     if("$imgdir/$a_img[$x]" !="")  
  207. print "<td align=center valign=top>";  
  208. print "<TABLE WIDTH=198 BORDER=0 CELLPADDING=0 CELLSPACING=0>";  
  209. print "<TR><TD COLSPAN=3><IMG SRC=\"$place/slidev_01.gif\" WIDTH=198 HEIGHT=28></TD></TR>";  
  210. print "<TR><TD><IMG SRC=\"$place/slidev_02.gif\" WIDTH=56 HEIGHT=130></TD>";  
  211.   
  212. echo '<td><a href="', urlencode($imgdir), '/', urlencode($a_img[$x]),'">';  
  213.   
  214. print "<img src=\"$thumbnail\" height=$height width=$width border=0 alt='$a_img[$x]' style=\"filter:alpha(opacity=100)\" onmouseout=\"gradualfade(this,100,30,4)\" onmouseover=\"gradualfade(this,40,50,100)\"></a></TD>";  
  215. print "<TD><IMG SRC=\"$place/slidev_04.gif\" WIDTH=56 HEIGHT=130></TD></TR><TR>";  
  216. print "<TD COLSPAN=3><IMG SRC=\"$place/slidev_05.gif\" WIDTH=198 HEIGHT=31><br><font size=\"1\">";  
  217. caption($caption_name);  
  218. print "</TD></TR>";  
  219. print "</TABLE>";  
  220. print "</td>\n";  
  221. }     
  222. }  
  223.   
  224.    if(($x%$col) == ($col-1))  
  225.    {  
  226.     print "</tr>\n";  
  227.     $r++;  
  228.    }  
  229.   // print "r=$r - maxrow=$maxrow<br>";  
  230.    if($r==$maxrow)  
  231.    {  
  232.     break;  
  233.    }  
  234.    else  
  235.    $x++;  
  236.   }  
  237.   print "</table>\n </div>";  
  238.  }  
  239.  // page break  
  240.    
  241.   
  242.   
  243. $imgdir = str_replace(" ""%20"$imgdir);   
  244.   
  245. //page number  
  246. print "<p><font size=2 face=verdana>";  
  247.  if($totimg>$totxpage)  
  248.  {  
  249.   if($totpages>$page)  
  250.   {  
  251.    $next = $page+1;  
  252.    $back = ($page>1)?($page-1):"1";  
  253.    if($page>1)  
  254.    {  
  255.     $back = $page-1;  
  256.     print "<a href=index.php?imgdir=$imgdir&page=1>first page</a> | <a href=index.php?imgdir=$imgdir&page=$back><< back </a>";  
  257.    }  
  258.    print " &nbsp;&nbsp; <b>page $page of $totpages</b> &nbsp;&nbsp;<a href=index.php?imgdir=$imgdir&page=$next>next >></a> | <a href=index.php?imgdir=$imgdir&page=$totpages>last page</a>";  
  259.   }  
  260.   else  
  261.   {  
  262.    $next = (($page-1)==0)?"1":($page-1);  
  263.    print "<a href=index.php?imgdir=$imgdir&page=1>first page</a> | <a href=index.php?imgdir=$imgdir&page=$next><< back</a>&nbsp;&nbsp; <b>page $page of $totpages</b> &nbsp;&nbsp;";  
  264.   
  265. print "</center>";  
  266.   }  
  267.  }  
  268. include("footer.inc");  
  269.   
  270. print'  
  271. </ body>  
  272. </ html>  
  273. ';  
  274. ?>  
6

Rövidebben?

Poetro · 2011. Szep. 2. (P), 12.25
Most ideszórtál egy jó nagy halom kódot, amiből nem derült ki, hogy pontosan mi is a problémád. Le tudnád redukálni annyira, amennyi a probléma reprodukálásához szükséges? Mert a fenti kódnak a 99%-ban valami olyasmi van, ami biztosan nem tartozik hozzá.
7

Röviden...

kranyo · 2011. Szep. 2. (P), 12.43
Igazad van...
Röviden:
Az index.php alapból kilistázza a vele azonos könyvtárban (config.php-ben akkor ez áll: $dir = ".";) lévő könyvtárakat és ki rakja linkként a nevüket. Ha rákattintok akkor pedig megjelennek a benne lévő képek.Én azt szeretném, hogy az index.php mellet legyen egy gal nevű mappa amiben a többi mappa van a képekkel (csak ezek a mappák jelenjenek meg)
Ezt próbáltam így: config.php-ben: $dir = "./gal";
(de próbáltam már ezer módon megadni, pl. teljes útvonallal...)
config.php-ben:
  1. $dir = "./gal";  
index.php
  1. $dh = @opendir($dir);  
  2.   while($file = readdir($dh))  
  3.  {  
  4. if ($file != "." && $file != ".."&& is_dir($file))     
  5. {$dname[] = $file;  
  6. sort($dname);  
  7. reset ($dname);  
  8.  }  
  9. }  
  10. print "<script language=\"JavaScript\">";  
  11. print "function MM_jumpMenu(targ,selObj,restore){eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");";  
  12. print "  if (restore) selObj.selectedIndex=0;}";  
  13. print "</script>";  
  14. $u=0;  
  15. print"<table>";  
  16.  foreach($dname as $key=>$val)  
  17.   {    
  18.   if($dname[$u])     
  19.     {   
  20.         if(($u%5)==0)  
  21.         {  
  22.             print"<tr>";  
  23.         }  
  24.         print"<td><a href=\"index.php?imgdir=$dname[$u]\">$dname[$u]</a></td>";  
  25.         $u++;  
  26.     }  
  27.   }  
  28. print"</table>";  
Köszönöm!
8

Elérési út

Poetro · 2011. Szep. 2. (P), 13.42
  1. <?php  
  2. $dir = './gal';  
  3. $dirlist = array();  
  4. if (is_dir($dir)) {  
  5.   $dh = opendir($dir);  
  6.   while ($directory = readdir($dh)) {  
  7.     // Ellenőrízzük, a könyvtár elérési útját  
  8.     if ($directory != '.' && $directory != '..' && is_dir($dir . '/' . $directory)) {   
  9.       $dirlist[] = $directory;  
  10.     }  
  11.   }  
  12. }  
  13. natsort($dirlist);  
  14.   
  15. if (count($dirlist)):  
  16. ?>  
  17. <table>  
  18.   <tbody>  
  19. <?php foreach ($dirlist as $key => $name) : ?>  
  20.     <?php if ($key % 5 === 0) echo $key !== 0 ? "</tr>\n<tr>\n" : "<tr>\n"; ?>  
  21.       <td>  
  22.         <a href="index.php?imgdir=<?php echo rawurlencode($name); ?>">  
  23.           <?php echo $name; ?>  
  24.         </a>  
  25.       </td>  
  26. <?php endforeach; ?>  
  27.     </tr>  
  28.   </tbody>  
  29. </table>  
  30. <?php endif; ?>  
9

Köszi!

kranyo · 2011. Szep. 2. (P), 14.09
Nagyon Köszönöm!