473,425 Members | 1,747 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,425 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 2959
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
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,...
0
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...

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.