472,371 Members | 1,361 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

read images from directory

anfetienne
424 256MB
hi,

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
  1.  
  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;
  9.  
  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. }
  30.  
  31. if($r>0) {
  32. for($m=$r; $m<5; $m++) {
  33. echo "<td>&nbsp;</td>";
  34. }
  35. }
  36.  
  37. ?>
  38.  
Jun 8 '09 #1
16 4029
Dormilich
8,658 Expert Mod 8TB
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
anfetienne
424 256MB
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
Dormilich
8,658 Expert Mod 8TB
start here. from there on it should not be too difficult.
Jun 8 '09 #4
anfetienne
424 256MB
ok asort() & ksort() seems to be a good and simple choice...from my coding which do i add asort() to?

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


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.  
Jun 8 '09 #5
Dormilich
8,658 Expert Mod 8TB
@anfetienne
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
anfetienne
424 256MB
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/theauctionwinners.com/httpdocs/resources/templateEdit.php on line 473

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

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

@anfetienne
see post above
Jun 8 '09 #8
anfetienne
424 256MB
its just strange how it wont show the images in the correct order
Jun 8 '09 #9
Dormilich
8,658 Expert Mod 8TB
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
anfetienne
424 256MB
it sorts incorrectly.....the files are uploaded and renamed correctly but once it gets to reading the directory and putting it in table format it sorts incorrectly....have i done anything wrong in the coding?
Jun 8 '09 #11
Dormilich
8,658 Expert Mod 8TB
where did you sort the array?
Jun 8 '09 #12
anfetienne
424 256MB
it's sorted in the only place where the array exists and thats when it's displayed....within the same coding i've posted
Jun 8 '09 #13
anfetienne
424 256MB
hi can anyone help me? i have tried sorting and i still can't get them to order correctly???
Jun 15 '09 #14
Dormilich
8,658 Expert Mod 8TB
how are they ordered currently, and how would you like them to be?
Jun 15 '09 #15
anfetienne
424 256MB
they are ordering 1,3,2,4,6,5.....etc its all jumbled and i'd like them to be ordered 1,2,3,4,5,6,7,8
Jun 15 '09 #16
anfetienne
424 256MB
i've tried everything i could think of but can't get it to work.

is it possible to order images within a directory by their name rather than letting php just order it how it wants to?

this is my code

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.  
Jun 18 '09 #17

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

Similar topics

1
by: Ken Tech | last post by:
Anybody know references about how to read active directory value from asp.net pretty urgent! thanks, Ken
3
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...
3
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...
3
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...
4
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.
1
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.
2
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
0
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...
4
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,...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.