need help displaying multiple thumbnails

I an a php novice and I am trying to display thumbnails, .jpeg files, in a table that are store in a file /thumbs. The file names are stored in a MySql table. I have a .php script that displays the files if there is only one item in the table. However, once there is more 1 record in the table the same file is displayed no matter what the name of the file is. The code below is image.php. This is the code that displays the thumbnail. Below is the script the builds the table.

<?php session_start(); $imagepath = $_SESSION['Thumbnail']; $image=imagecreatefromjpeg($imagepath); header('Content-Type: image/jpeg'); imagejpeg($image); unset($_SESSION['Thumbnail']); ?>

The name of the file is in the session variable $_SESSION[‘Thumbnail’].

The code that accesses this file is below. The name of the image file is retrieved from the data base and stored in the session variable $_SESSION[‘Thumbnail’]. Each time throught the while loop. If I run this code I get a table with the Image name, stored in $_SESSION[‘Thumbnail’], displayed but the image is always the same. What ame I doing wrong?

<?php session_start(); include("functions_main.inc"); include("Overpar.inc"); $Images = items_forsale("Overpar.inc"); ?>
      <?php
	  while($row = mysqli_fetch_row($Images)) {
	     $_SESSION['Thumbnail'] = "thumbs/tn_".$row[1];
         echo "<tr>
	          <td>$_SESSION[Thumbnail]</td>
              <td WIDTH=110><img src=\"image.php\"></td>
   		   </tr>";
		}	
       ?>
    </table>
</body>

Any help would be appreciated.

Thanks,
Bob

Image Name Image

Hi there,

Forgive me if I am missing something, but surely you are wanting the image tag to have src="$_SESSION[‘Thumbnail’]" ?

Ok - thanks for that. It works, kind of. If there is a space in the file name it doesn’t show the file. If I check the properties the file name is “http://localhost/dcmc/thumbs/tn_3501Water” where the true value of of $_SESSION[Thumbnail] is “http://localhost/dcmc/thumbs/tn_3501Water lilies.jpeg”. If I remove the space in the file name it works.

Bob

Yea, you’ll want to clean the filenames when the images are uploaded to have no spaces, but you could try

[php]
str_replace(" “,”+",$_SESSION[‘Thumbnail’])
[/php]

or

[php]
str_replace(" “,”%20",$_SESSION[‘Thumbnail’])
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service