473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

wrong order of images with readdir()

Hi guys....
i know this question has been asked already and I found a few answers but it would be soo great if anyone could help me with this script, which just browses images on a webpage in an image folder on a server.

the script so far is working (a friend gave it to me):

http://dev.perfectday.gb.com/tom/chiaraweb/photo.php

the number on the images are the filenames. I want to order the images by filenames.

the only thing is the order of the images.
I know there is a way with scandir but as I am a beginner with php I am not able to fit the right piece of code into the right bit of my photos.php.

if anyone could tell me how I can make this work would be amazing.
I am making this website for a freind so that I cannot hire any programmer for that :(

this is the code of the photo.php.

I didnt ue the part with the category.

thanks a lot
kirstenkirsche
.............................................

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Chiara Romagnoli Photographer</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <link href="style.css" rel="stylesheet" type="text/css">
  6. <script type="text/javascript">
  7. <!--
  8. function MM_preloadImages() { //v3.0
  9.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  10.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  11.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  12. }
  13. //-->
  14. </script>
  15. </head>
  16.  
  17. <body>
  18. <table align="center" cellpadding="0" cellspacing="0">
  19.   <tr>
  20.     <td><a href="index.html"><img src="pictures/header.gif" alt="Chiara Romagnoli Photographer" width="501" height="84" /></a></td>
  21.   </tr>
  22.   <tr>
  23.     <td><div align="right"><a href="photo.php"><img src="pictures/gallery.gif" alt="gallery" width="62" height="20"></a><a href="about.html"><img src="pictures/about.gif" alt="about" width="60" height="20"></a><a href="contact.html"><img src="pictures/contact.gif" alt="contact" width="75" height="20"></a></div></td>
  24.   </tr>
  25. </table>
  26. <table border="0" cellspacing="0" cellpadding="5" align="center">
  27.   <tr>
  28.     <td align="center">
  29.       <table border="0" cellspacing="0" cellpadding="0">
  30.         <tr>
  31.           <td>
  32.             <div align="center"><br>
  33. <?php
  34.  
  35. $Pfadcat1 = "./pictures/gallery/";
  36. $Pfadcat2 = "./photos/2/";
  37. $Pfadcat3 = "./photos/3/";
  38.  
  39. #echo "<hr>index-übergeben<br>"."$index"."<hr>";
  40. #echo "<hr>cat-übergeben<br>"."$cat"."<hr>";
  41.  
  42.  
  43. #echo "Per POST übergebene Variablen:<br>\n";
  44. while (list ($key, $val) = each ($_GET))
  45. {
  46.     #echo "$key => $val<br>";
  47.     if ($key=="cat")
  48.     {
  49.      $cat=$val;
  50.     }
  51.     if ($key=="index")
  52.     {
  53.      $index=$val;
  54.     }
  55. }
  56.  
  57. #echo "<hr>index-übergeben<br>$index<hr>";
  58. #echo "<hr>cat-übergeben<br>$cat<hr>";
  59.  
  60. if ($cat==1)
  61. {
  62.  $Pfad = $Pfadcat1;
  63. }
  64. if ($cat==2)
  65. {
  66.  $Pfad = $Pfadcat2;
  67. }
  68. if ($cat==3)
  69. {
  70.  $Pfad = $Pfadcat3;
  71. }
  72. if (($cat!=1)&&($cat!=2)&&($cat!=3))
  73. {
  74.  $Pfad = $Pfadcat1;
  75. }
  76.  
  77. #echo $Pfad;
  78. #echo "<hr>index-übergeben<br>$index<hr>";
  79. #echo "<hr>cat-übergeben<br>$cat<hr>";
  80.  
  81. $counter = 0;
  82. #anzahl datein ermitteln
  83. $i=0;
  84. $verz=opendir ($Pfad);
  85. while ($file=readdir($verz))
  86.  
  87.  
  88.  
  89. {
  90.     if (filetype($Pfad.$file)!="dir")
  91.     {
  92.         $i++;
  93.         #echo "<br>.$file";
  94.  
  95.  
  96.     }
  97. }
  98. closedir($verz);
  99. #linkzähler ermitteln
  100. #echo "<hr>anzn<br>".$i."<hr>";
  101. #sicherheit
  102. if($index<1||$index>$i)
  103. { $index = 1;}
  104.  
  105. $prev = $index-1;
  106. $next = $index+1;
  107. if($prev<1)
  108. { $prev = $i;}
  109. if($next>$i)
  110. { $next = 1;}
  111.  
  112. if($Verzeichniszeiger = opendir($Pfad))
  113. {
  114.     while($Datei = readdir($Verzeichniszeiger))
  115.     {
  116.         if($Datei != "." && $Datei != "..")
  117.         {
  118.             $Bilddaten = getimagesize($Pfad.$Datei);
  119.             $counter++;
  120.             #echo "<hr>".$counter."<hr>";
  121.  
  122.             if($index==$counter)
  123.             {
  124.  
  125. ?>
  126.               <table border="0" align="center" cellpadding="5" cellspacing="0">
  127.  
  128.                 <tr>
  129.                   <td colspan="3">
  130.                     <div align="center">
  131.                       <table width="100" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF">
  132.                         <tr>
  133.                           <td>
  134.                             <div align="center"><a href="photo.php?index=<?php echo$next; ?>&cat=<?php echo$cat; ?>"><img src="<?php echo$Pfad.$Datei; ?>"></a><br>
  135.                           <?php
  136.             }
  137.         }
  138.     }
  139.     closedir($Verzeichniszeiger);
  140. }
  141. #echo "<hr>".$counter."<hr>";
  142. ?> </div> </td>
  143.                       </tr>
  144.                         </table>
  145.                   </div></td>
  146.                 </tr>
  147.                 <tr valign="top">
  148.                   <td height="25"><a href="photo.php?index=<?php echo$prev; ?>&cat=<?php echo$cat; ?>"><img src="images/button1.gif" alt="1" border="0"></a></td>
  149.                   <td height="25"><div align="center"></div></td>
  150.                   <td height="25"><div align="right"><a href="photo.php?index=<?php echo$next; ?>&cat=<?php echo$cat; ?>"><img src="images/button2.gif" alt="2" border="0"></a></div></td>
  151.                 </tr>
  152.  
  153.               </table>
  154.             </div>          </td>
  155.         </tr>
  156.        </table>    </td>
  157.   </tr>
  158. </table>
  159. <div align="center"></div>
  160. </body>
  161. </html>
Oct 8 '08 #1
2 2457
Markus
6,050 Expert 4TB
Hey there, Kirsten.

When posting code on the forums, be sure to use [code] tags. [code] .. code goes here [/code]. If you neglect to do so, you will be given a warning and possibly a temporary ban. Please read the Posting Guidelines on How To Ask A Question

Markus.
Oct 8 '08 #2
pbmods
5,821 Expert 4TB
Heya, kirstenkirsche.

Use scandir() to store the filenames in an array (http://php.net/scandir), then use sort() to sort the array (http://php.net/sort).
Oct 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: phatnugs420 | last post by:
Hi all I'm a newbie and I need a good starting off point. Basically is there a way in php where you can call up all images (jpgs and gifs) within a directory. Also is there a way to format the...
5
by: Davide | last post by:
Hi all. With this simple script I can see all my jpg in a web page.. but they are confused randomly in the page. is there a way to put them alfabetically? from A to Z? thanx <?php if...
2
by: chiara | last post by:
Hi! This is a piece of a code I wrote. It was perfectly working but now it is giving me some problems I can not understand. I scan a directory (ss_data) and I count its alaments. then I print...
15
by: Jameson | last post by:
Happy New Year, Everyone! I am trying to figure out how to display a bunch of images (mainly JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a local directory on the system....
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
4
by: MZ | last post by:
Hello! I have written such function... Unfortunately images are not sorted by filename and I don`t know why. I have such files placed in subfolder: ...
1
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires...
2
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
9
by: Confused but working on it | last post by:
Just wanted to say thanks for the posts helping me make ths work. Added a few comments and after the readdir used a pattern match to test for ..jpg, and seems to work fine on my test setup. Maybe I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.