473,943 Members | 12,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wrong order of images with readdir()

1 New Member
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 2483
Markus
6,050 Recognized Expert Expert
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 Recognized Expert Expert
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
1926
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 images to come up in rows. Hope this makes sense. Thanks in advance for the help. Mikey p...
5
1722
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 ($handle = opendir('/cover')) {
2
1710
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 the name of each file in the directory before opening it.Even if the names of the files are stored correctly in the memory the program prints the letter 'E'(the files are named differently, e.g.traind05c1__a.1.1.1.3.fasta). The program correctly...
15
22337
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. I can do this with the glob() function, but I can't seem to put in a directory other than one within the webroot. For example, I can only put "/uploads" and not "/Volumes/jray/Pictures...". Any ideas how to get around this? If I can't use the...
10
13442
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 a problem. I am using chunk_split(data) and the base64_encode and base64_decode on the files. I do a select from the database, and then echo the image (with header(Content Type: image/jpeg) and the decoded image displays fine. Yes, I have...
4
45040
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: 2005_11_17_koncert_Riverisde_w_Poznaniu_1.jpg 2005_11_17_koncert_Riverisde_w_Poznaniu_2.jpg
1
4164
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires PHP and GD2 if you wish to use the
2
3107
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
9
3544
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 should test for gif, tiff, and png... Anyway, here's the code: <?php //Open images directory $dir = opendir("images"); //read files in the dir while (($file = readdir($dir)) !== false) //test to make sure jpg
0
9970
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10662
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9865
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8219
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6308
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4910
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.