5 Replies - 3500 Views - Last Post: 31 December 2008 - 08:01 AM Rate Topic: -----

#1 Ghost rider  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 158
  • Joined: 29-October 08

how to view all images stored in directory?

Posted 30 December 2008 - 04:49 AM

In this script I can view only one image that's in my directory and also it display all details of images that are save in database but without images. How can I view all the images that are in directory? that only trouble? Thanks in advance.

<?php 
// Get our database connector
require("conn.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	 <head>
		  <title>Dream in code tutorial - List of Images</title>
	 </head>

	 <body>
	 
		  <div>

			   <?php	 
					// Grab the data from our upload2 table
					$sql = "select * from upload2";
					$result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());

					while ($row = mysql_fetch_assoc($result))
					{
						 echo "<div class=\"picture\">";
						 echo "<p>";

						 // Note that we are building our src string using the filename from the database
			 echo $row['name'] . " <br />";
						 echo "<img src=\"images/". $row['name'] . "\" alt=\"\" /> <br />";
						
						 echo "</p>";
						 echo "</div>";
					}

			   ?>
		  
		  </div>
	 </body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: how to view all images stored in directory?

#2 mazeroth  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 11-December 08

Re: how to view all images stored in directory?

Posted 30 December 2008 - 09:17 AM

You want to only show images from a folder right? Not from a database? If so, you need to open the folder, look through all the files to see which is an image, then just display them:

$dir = 'path/to/folder/';
$files = opendir($dir);
while($file = readdir($files)) preg_match('/(.png)|(.gif)|(.jpg)/i',$file) ? 
		$images[] = array($file,substr($file,strlen($file)-3)) : null;



The above will open the folder dir, then loop through the files in dir and populate the array images with all the jpgs, gifs, and pngs. Now you can do what ever you need with the images array. Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 Ghost rider  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 158
  • Joined: 29-October 08

Re: how to view all images stored in directory?

Posted 30 December 2008 - 01:09 PM

Thanks for your help. But the script above is display the filenames that are stored in database and pictures that are save in directory(server) together on brownser. because I didn't want to save pictures in
database. That meant the script is displaying filanames that are in database and the pictures that are in directory.
The trouble's that it is just displaying one pictures and other pictures displaying missing source(red X instead of image) on brownser. Please could you just check my code! Thank
Was This Post Helpful? 0
  • +
  • -

#4 mazeroth  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 11-December 08

Re: how to view all images stored in directory?

Posted 30 December 2008 - 01:35 PM

Can you run your script and view source of the page with the broken images and paste it here so we can see what's going on. Are you sure all the images from the upload2 table are physically in the images folder?
Was This Post Helpful? 0
  • +
  • -

#5 Ghost rider  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 158
  • Joined: 29-October 08

Re: how to view all images stored in directory?

Posted 30 December 2008 - 01:59 PM

View Postmazeroth, on 30 Dec, 2008 - 12:35 PM, said:

Can you run your script and view source of the page with the broken images and paste it here so we can see what's going on. Are you sure all the images from the upload2 table are physically in the images folder?


Yeah, all are in images folder.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
	 <head>
		  <title>Dream in code tutorial - List of Images</title>
	 </head>

	 <body>
	 
		  <div>

			   <div class="picture"><p>1.jpg <br /><img src="images/1.jpg" alt="" /> <br /></p></div><div class="picture">
		   <p>1.jpg <br /><img src="images/1.jpg" alt="" /> <br /></p></div><div class="picture">
		  <p>3.jpg <br /><img src="images/3.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>8.jpg <br /><img src="images/8.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>4.jpg <br /><img src="images/4.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>4.jpg <br /><img src="images/4.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>4.jpg <br /><img src="images/4.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>12.jpg <br /><img src="images/12.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>12.jpg <br /><img src="images/12.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>12_1.jpg <br /><img src="images/12_1.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>15.jpg <br /><img src="images/15.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>16.jpg <br /><img src="images/16.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>1.jpg <br /><img src="images/1.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>5.jpg <br /><img src="images/5.jpg" alt="" /> <br /></p></div><div class="picture">
			  <p>Picture 002.jpg <br /><img src="images/Picture 002.jpg" alt="" /> <br /></p></div>		  
		  </div>
	 </body>
</html>

note:8.jpg is the only pictures is display on brownser.
Was This Post Helpful? 0
  • +
  • -

#6 mazeroth  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 11-December 08

Re: how to view all images stored in directory?

Posted 31 December 2008 - 08:01 AM

Is this up live somewhere - do you have url we can go to view these images? Everything seems fine, I'd like to to try to access theses images and see what happens.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1