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

upload and display images

anfetienne
424 256MB
Hi,

i went through a tutorial on how to display images stored with a directory and it came out good but i have a problem.....when i upload less than 5 files it displays the 1 image and then shows broken image placeholders. If i don't upload in sums of 5 then these broken image places holders keep showing, and instead of the images displaying row by row it goes by columns.

Below is the code to display....can someone tell me where i've gone wrong or how i can change this so it displays the uploaded images in rows of 5?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $folderPath= $id;
  4. $full_path=$fileL;
  5.  
  6. $path = "$folderPath"; // path to the directory to read ( ./ reads the dir this file is in)
  7. if ($handle = opendir($path)) {
  8.    while (false !== ($file = readdir($handle))) {
  9.     if ($file != "." && $file != "..") {
  10.         if(!is_dir($file)){
  11.             $item[] = $file;
  12.             }
  13.        }
  14.    }
  15.    closedir($handle);
  16. }
  17.  
  18. $total_items = count($item);
  19. $max_items = ceil($total_items / 5); // items per <td>
  20. $start = 0;
  21. $end = $max_items
  22.  
  23. //generate the table
  24. ?>
  25. <center>
  26. <table width="650px" border="1" cellspacing="5" cellpadding="5" align="center">
  27.   <tr>
  28. <?php
  29. require_once 'js/iframeRS.js'; 
  30.     for($i=0; $i<5; $i++){
  31.         if($i != 0){
  32.             $start = $start + $max_items;
  33.             $end   = $end + $max_items;
  34.         }
  35.  
  36.         echo "<td>";
  37.         for($x = $start; $x < $end; $x++){
  38.       $imageL= $path.$item[$x];
  39.       $img_path="http://ve-creative.com/test/8/$imageL";
  40.             // display the item
  41.             echo '<center><p><img src= "'.$path.$item[$x] .'" height="100" width="100"></p></center>';
  42.             echo "<input type=CHECKBOX name=$imageL>";
  43.             echo "<a href=imgEdit.php?img=$img_path>[Edit / resize]</a><br>";        }
  44.     echo "</td>";
  45.     }
  46.  
  47.     ?>
  48.   </tr>
  49. </table>
  50.  
  51.         </div>          <!--end:mult.pictures-->
  52.  
  53.  
  54.           <table width="100%" border="0" cellpadding="5">
  55.  
Feb 26 '09 #1
14 2944
devsusen
136 100+
After looking at a glance I found two problem in your code.

First one is
Expand|Select|Wrap|Line Numbers
  1. $max_items = ceil($total_items / 5); // items per <td>
if the $total_items is less 5 then the expression will always produce 1 in $max_items.

Second is in your 2 nested for loop in the display part. For the outermost loop you will always get 5 cells in the table. Each cell will contain atleast one image placeholder and related link.

I think you should check the total no. of images while displaying them in the table. Here is the snippet
Expand|Select|Wrap|Line Numbers
  1. <center>
  2. <table width="650px" border="1" cellspacing="5" cellpadding="5" align="center">
  3.   <tr><td>
  4. <?php
  5. for($n=0; $n<$total_items; $n++) {
  6.    if($n !=0 && fmod($n, 5) == 0) {
  7.       echo "</td><td>";
  8.    }
  9.    echo '<center><p><img src= "'.$path.$item[$x] .'" height="100" width="100"></p></center>';
  10.    echo "....other lines.....";
  11. }
  12. ?>
  13.   </tr>
  14. </table>
Hope this will help.
Feb 26 '09 #2
anfetienne
424 256MB
hi, it helped some what....it shows the images perfectly fine and doesn't show the broken placeholder but it is displaying in 1 column....i am trying to get it to show in rows at max of 5 images per row
Feb 26 '09 #3
devsusen
136 100+
@anfetienne
Your display logic is not very clear to me. Can you put the dummy output HTML code for two cases like 3 images and 7 images. Once I see the HTML code I may try to help you with the php coding.
Feb 27 '09 #4
Markus
6,050 Expert 4TB
Check out this old post. It'll help you display your images in rows and columns.
Feb 27 '09 #5
devsusen
136 100+
@Markus
I have gone through the above mentioned thread. Now it seems to me that display should looks like a martix, so here is another version of code for that:
Expand|Select|Wrap|Line Numbers
  1. <center>
  2. <table width="650px" border="1" cellspacing="5" cellpadding="5" align="center">
  3.   <tr><td>
  4. <?php
  5. $r = 0;
  6. for($n=0; $n<$total_items; $n++) {
  7.    if($n !=0 && fmod($n, 5) == 0) {
  8.       echo "</tr><tr>";
  9.    }
  10.    echo '<td><center><p><img src= "'.$path.$item[$x] .'" height="100" width="100"></p></center>';
  11.    echo "....other lines.....</td>";
  12. }
  13.  
  14. if($r>0) {
  15.   for($m=$r; $m<5; $m++) {
  16.    echo "<td>&nbsp;</td>";
  17.   }
  18. }
  19. ?>
  20.   </tr>
  21. </table>
Feb 27 '09 #6
anfetienne
424 256MB
thank you guys for the help and advice i will test the last code and see how it displays
Feb 27 '09 #7
anfetienne
424 256MB
hi it still does not work....it shows the last 2 images in a row like it should....

here is the web address to the testing page....upload images and see what it does

http://ve-creative.com/test/8/templateEdit2.php
Feb 27 '09 #8
anfetienne
424 256MB
here is the dummy html code

Expand|Select|Wrap|Line Numbers
  1. <center><p><img src= "upload/71947137/1.jpg" height="100" width="100"></p></center><input type=CHECKBOX name=upload/71947137/1.jpg><a href=imgEdit.php?img=http://ve-creative.com/test/8/upload/71947137/1.jpg>[Edit / resize]</a><br></td><center><p><img src= "upload/71947137/2.jpg" height="100" width="100"></p></center><input type=CHECKBOX name=upload/71947137/2.jpg><a href=imgEdit.php?img=http://ve-creative.com/test/8/upload/71947137/2.jpg>[Edit / resize]</a><br></td><center><p><img src= "upload/71947137/3.jpg" height="100" width="100"></p></center><input type=CHECKBOX name=upload/71947137/3.jpg><a href=imgEdit.php?img=http://ve-creative.com/test/8/upload/71947137/3.jpg>[Edit / resize]</a><br></td><center><p><img src= "upload/71947137/4.jpg" height="100" width="100"></p></center><input type=CHECKBOX name=upload/71947137/4.jpg><a href=imgEdit.php?img=http://ve-creative.com/test/8/upload/71947137/4.jpg>[Edit / resize]</a><br></td><center><p><img src= "upload/71947137/5.jpg" height="100" width="100"></p></center><input type=CHECKBOX name=upload/71947137/5.jpg><a href=imgEdit.php?img=http://ve-creative.com/test/8/upload/71947137/5.jpg>[Edit / resize]</a><br></td>   </tr>
  2.  
  3.  </table>
  4.  
Feb 27 '09 #9
devsusen
136 100+
In IE and FF its displaying perfectly alright. I have tested by uploading 3 and 5 images. Have u corrected ur code? In the dummy HTML code I found the </td> tag missing.
Mar 2 '09 #10
anfetienne
424 256MB
i've coorected the code somewhat and it lines up almost as it should....then only problem now is there is a blank space at the start of the 1st row as if there should be an image there.
Mar 2 '09 #11
Markus
6,050 Expert 4TB
If you look at the source code your page produces, you will see you output an empty <td>. Looking at the code in this post, you can see on line 3 a <td> that shouldn't be there. Remove it, job's a good'un.
Mar 2 '09 #12
anfetienne
424 256MB
THAT'S GREAT!!!!! thanks for all the help.....what took you a few posts I couldn't even get a reply on other forums....thanks alot!!!
Mar 2 '09 #13
Markus
6,050 Expert 4TB
That's why Bytes.com rules.

Take care,

Markus.
Mar 2 '09 #14
anfetienne
424 256MB
is it possible to upload images and have them renamed like below???

1
1b
2
2b
3
3b
4
4b etc etc
Mar 3 '09 #15

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

Similar topics

1
by: Dean | last post by:
First I've must say Im completly new in php scripting What I need to do is upload, resize pictures with path in database Here is theory of it, and plan of doing it Hope somebody can help me...
4
by: NohaKhalifa | last post by:
Dear All; I'm developing a web site and i need to make adminisration for this site it's a site for Real Estates . But I don't need the administration to be online .. I want them to fill data...
2
by: puja | last post by:
hi all, I have website build using c# where I have 3 images in my homepage. I have a table called images where I store the physical path of all 3 images. eg: Image1 -->...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
3
by: Jefferis NoSpamme | last post by:
Hello all, I'm trying to limit the file size to 1 meg on upload of image files and I am trying a script from javascript internet, but it is giving me errors on IE ² is null or not an object ³...
13
by: honey99 | last post by:
hi! i have a table..which consists of a upload and browse buttons and some place to display an image.if i browse a file(jpg,gif) and upload,it should appear in place of image in that table...
5
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
1
by: mms003 | last post by:
i would like to know how to sort whe a a user upload there photos, hwo can i display it by the title and when they click on the title it will sho all the image that user upload... also sort by dat......
2
by: kelvinwebdesigner | last post by:
Hi everybody. Im currently developing an application where users can upload files and later get acess to the url. Im now having this trouble with header Cannot modify header information – headers...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.