473,698 Members | 2,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

upload and display images

anfetienne
424 Contributor
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.....whe n 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 2990
devsusen
136 New Member
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 Contributor
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 New Member
@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 Recognized Expert Expert
Check out this old post. It'll help you display your images in rows and columns.
Feb 27 '09 #5
devsusen
136 New Member
@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 Contributor
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 Contributor
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 Contributor
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 New Member
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

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

Similar topics

1
3725
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 here are 4 sizes of images:
4
2418
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 and images offline and then send them online... but i have a problem regarding the images i want it to be sent to the web site So i want if there is a possible way to fill data offline and
2
1587
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 --> C:\StoreImages\User1\Image1.jpj Image2 --> C:\StoreImages\User1\Image2.jpj Image3 --> C:\StoreImages\User1\Image3.jpj When my website loads, I read this table to populate images.
9
3831
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 site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
3
13136
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 ³ and isn¹t checking the file size or preventing the upload. ERROR IS <<<<Œthis.form.uploadfile.value² is null or not an object on this line:
13
6854
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 itself.my code is <form method="POST" ENCTYPE="multipart/form-data" ACTION="abc.Action"> <table cellpadding=0 cellspacing=0 border=0 style='top:40px;left:0px;position:absolute;z-index:0;' width=130px > <TR> <TD vAlign=top width=8...
5
3288
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 _uploadedfiles_xxxx) (php must be allowed to move uploaded files to this folder' - uploadedfiles_xxxx. I typed <?php chmod ('_uploadedfiles_xxxx',640); ?> into notepad and saved it as php in the uploaded_xxxx folder, when I went to test it, the error...
1
1493
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... i have where it will display all the images by any field... Ascending or Descending. i want to some how group by user upload. Thanks.
2
2671
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 already sent This is my code so far <?php #script 10.52 - show_image.php $name = FALSE;//flag variable: //check for an image in the URL: if (isset($_GET)){ //Full image path:
0
8683
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, 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...
0
8611
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,...
0
9170
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, 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...
0
9031
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 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...
0
7741
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, 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...
1
6531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
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.