473,386 Members | 1,820 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,386 software developers and data experts.

how to sort images after readdir numerically

anfetienne
424 256MB
Hi,

What would be the best way or how should i say do i sort images that are named numerically in order?

this is my original code, i was told that it should sort perfecty fine with what ive got but it doesn't.....its all mixed up

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $path = "upload/$random_digit/images/"; // path to the directory to read ( ./ reads the dir this file is in)
  4. if ($handle = opendir($path)) {
  5.    while (false !== ($file = readdir($handle))) {
  6.     if ($file != "." && $file != "..") {
  7.         if(!is_dir($file)){
  8.             $item[] = $file;
  9.             }
  10.        }
  11.    }
  12.    closedir($handle);
  13. }
  14.  
  15. $total_items = count($item);
  16. $max_items = ceil($total_items / 5); // items per <td>
  17. $start = 0;
  18. $end = $max_items
  19.  
  20. //generate the table
  21. ?>
  22.  
  23.  
  24. <center>
  25. <table width="675px" border="0" cellspacing="5" cellpadding="5" align="center">
  26. <tr>
  27. <?php
  28. $r = 0;
  29. $pn=1;
  30. $pto=1;
  31.  
  32. for($n=0; $n<$total_items; $n++) {
  33. if($n !=0 && fmod($n, 5) == 0) {
  34. echo "</tr><tr>";
  35. }
  36.       $imageL= $path.$item[$n];
  37.      if (substr($imageL,-5) != 'b.jpg')
  38.      {
  39.       $img_path="http://theauctionwinners.com/resources/$imageL";
  40.       $editLink = "http://theauctionwinners.com/resources/imgEdit.php?img=$img_path";
  41.       $iframeName= 'if1';
  42.       $iframeHeight= '955px';
  43.       $click= 'onClick';
  44.             // display the item
  45.             echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
  46.             echo '<center><p><input type="hidden" name="picT[]" value="pic'.$pn++.'"/></p></center>';
  47.             echo '<center><p><input type="hidden" name="photoT[]" value="PHOTO '.$pto++.'"/></p></center>';
  48.             echo '<center><p><input type="text" name="captionT[]" value=""/></p></center>';
  49.             echo '<center><p><a href="'.$editLink .'" '.$click.'="document.getElementById('.$iframeName .').height='.$iframeHeight .'; document.getElementById('.$iframeName .').src=this.href; return false;"> > Edit Image < </a></p></center><br></td>';  
  50.     }
  51. }
  52.  
  53. if($r>0) {
  54. for($m=$r; $m<5; $m++) {
  55. echo "<td>&nbsp;</td>";
  56. }
  57. }
  58.  
  59. ?>
  60. </tr>
  61. <td><tr><center><input name="create" type="submit" value="Submit" /></center></tr></td>
  62. </form>
  63. </table>
  64.  
Jul 2 '09 #1
3 3866
Atli
5,058 Expert 4TB
The asort function should help with that.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $list = array(3, 6, 2, 5, 4, 1);
  3. asort($list);
  4.  
  5. print_r($list);
  6. ?>
Outputs:
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [5] => 1
  4.     [2] => 2
  5.     [0] => 3
  6.     [4] => 4
  7.     [3] => 5
  8.     [1] => 6
  9. )
  10.  
Jul 4 '09 #3
anfetienne
424 256MB
thanks for the help....in the end i used

sort($item,SORT_NUMERIC);

and it worked perfectly
Jul 7 '09 #4

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

Similar topics

13
by: .:mmac:. | last post by:
I am listing a set of files using the following script: <% set directory = Server.CreateObject("Scripting.FileSystemObject") set allfiles = directory.GetFolder(Server.MapPath("/mmm/lesson/"))...
6
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
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...
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: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi all, I have a "connected" datagridview that uses a bindingsource/datatable to load the grid and update the user's modifications to the database. I have a column that is set in the database...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
2
by: kirstenkirsche | last post by:
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.