473,699 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read images from directory

424 Contributor

I've got this piece of coding which displays the images within a folder and allows me to add captions to the images using xml. the problem im having is once it reads the folder it is mixing the images up....instead of listing them in order like 1,2,3,4,5 it starts with 1 and then any number will follow. how can i stop it from doing this.

here is the code
Expand|Select|Wrap|Line Numbers
  2. <center>
  3. <table width="675px" border="0" cellspacing="5" cellpadding="5" align="center">
  4. <tr>
  5. <?php
  6. $r = 0;
  7. $pn=1;
  8. $pto=1;
  10. for($n=0; $n<$total_items; $n++) {
  11. if($n !=0 && fmod($n, 5) == 0) {
  12. echo "</tr><tr>";
  13. }
  14.       $imageL= $path.$item[$n];
  15.      if (substr($imageL,-5) != 'b.jpg')
  16.      {
  17.       $img_path="http://theauctionwinners.com/resources/$imageL";
  18.       $editLink = "http://theauctionwinners.com/resources/imgEdit.php?img=$img_path";
  19.       $iframeName= 'if1';
  20.       $iframeHeight= '955px';
  21.       $click= 'onClick';
  22.             // display the item
  23.             echo '<td><center><p><a href="'.$img_path .'"><img src= "'.$path.$item[$n] .'" height="100" width="100"></a></p></center>';
  24.             echo '<center><p><input type="hidden" name="picT[]" value="pic'.$pn++.'"/></p></center>';
  25.             echo '<center><p><input type="hidden" name="photoT[]" value="PHOTO '.$pto++.'"/></p></center>';
  26.             echo '<center><p><input type="text" name="captionT[]" value=""/></p></center>';
  27.             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>';  
  28.     }
  29. }
  31. if($r>0) {
  32. for($m=$r; $m<5; $m++) {
  33. echo "<td>&nbsp;</td>";
  34. }
  35. }
  37. ?>
Jun 8 '09 #1
16 4112
8,658 Recognized Expert Moderator Expert
how do you determine $item? as it looks, you're displaying the images in the order of the array. maybe some of the array sorting functions will help you.
Jun 8 '09 #2
424 Contributor
i had to go through 3 tutorials to get this far with the code....where can i go for the array sorting functions tutorial?
Jun 8 '09 #3
8,658 Recognized Expert Moderator Expert
start here. from there on it should not be too difficult.
Jun 8 '09 #4
424 Contributor
ok asort() & ksort() seems to be a good and simple choice...from my coding which do i add asort() to?

asort($path.$it em[$n]); or asort($item[$n]); ?
ksort($path.$it em[$n]); or ksort($item[$n]); ?

Expand|Select|Wrap|Line Numbers
  1. <?php
  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. }
  15. $total_items = count($item);
  16. $max_items = ceil($total_items / 5); // items per <td>
  17. $start = 0;
  18. $end = $max_items
  20. //generate the table
  21. ?>
  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;
  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. }
  53. if($r>0) {
  54. for($m=$r; $m<5; $m++) {
  55. echo "<td>&nbsp;</td>";
  56. }
  57. }
  59. ?>
  60. </tr>
  61. <td><tr><center><input name="create" type="submit" value="Submit" /></center></tr></td>
  62. </form>
  63. </table>
Jun 8 '09 #5
8,658 Recognized Expert Moderator Expert
as described in the manual entry, asort() expects an array as input. thus
Expand|Select|Wrap|Line Numbers
  1. asort($item);
Jun 8 '09 #6
424 Contributor
i understand that but which is best for mine?

i just got an error from asort

Warning: asort() expects parameter 1 to be array, string given in /var/www/vhosts/theauctionwinne rs.com/httpdocs/resources/templateEdit.ph p on line 473

Warning: asort() expects parameter 1 to be array, string given in /var/www/vhosts/theauctionwinne rs.com/httpdocs/resources/templateEdit.ph p on line 473

Warning: asort() expects parameter 1 to be array, string given in /var/www/vhosts/theauctionwinne rs.com/httpdocs/resources/templateEdit.ph p on line 473
Jun 8 '09 #7
8,658 Recognized Expert Moderator Expert
well, ksort() will sort your array keys, which are already ordered, so it should not have any effect.

see post above
Jun 8 '09 #8
424 Contributor
its just strange how it wont show the images in the correct order
Jun 8 '09 #9
8,658 Recognized Expert Moderator Expert
except that "correct order" is very hard to teach a computer. do a var_dump() before and after sorting, so that you see how the sorting function actually sorts.
Jun 8 '09 #10

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

Similar topics

by: Ken Tech | last post by:
Anybody know references about how to read active directory value from asp.net pretty urgent! thanks, Ken
by: Csaba Gabor | last post by:
Not sure of best place for this question... Are there any built in images within the browser that I can assume (particularly IE and FF)? More specifically, I am writing a one file webApp.php application which needs one tiny little folder icon (e.g. http://us.geo1.yimg.com/pic.geocities.com/img/filemgr/folder.gif). Now I could have a second file of the folder icon, but I would rather only have one text file to distribute (namely,...
by: Andy | last post by:
HI all, I'm trying to read Active Directory from within an Asp.net application which is not impersonating any domain user. I'd like to allow the site to query the Active directory, but I want to make sure that the access is done in a secure way. What are the options and their benefits / drawbacks?
by: gencode | last post by:
I need to make a javascript read a web directory from a remote site (ie "http://remotesite.com/images") (The remote die does not have an index.htm and does have directory listing enabled) I have seen many samples but they all use frames or iframes, all I want is a method that you can say <body onload="readremotedir('http://remotesite.com/images');"> and the method would get the directory listings and populate an array
by: Michael Malinowski | last post by:
Is there a way to read the directory that the currently running python file is located in? Cheers Mike.
by: Salimunnisaa | last post by:
Hi all, Pls tell me how to read images from sql server database in asp.net. This is very urgent.
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
by: Anjan Bhowmik | last post by:
Hi, I use a form to upload an image to a directory on my site (~/Images/UserName/file1.jpg). Using Server.mapPath function i get the Physical path and save the file using FileUpload1.PostedFile.SaveAs(filePath) function. The file is saved fine. I also keep an daabase entry to store the virtual path (~/Images/UserName/file1.jpg) for that specific user entry. The problem is when i try to use...
by: bluewavessurf | last post by:
I want to implement a Perl Program that takes a directory path, ex (d:\programs) as an INPUT and this directory could have multiple files for this program let’s say 5 files (doc1, doc2, doc3, doc4, and doc5). This program should print the average time to open and read all these five files into OUTPUT. How can I read the files in blocks of 64 KB?
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
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();...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.