Current location: Hot Scripts Forums » Programming Languages » PHP » Showing images in a directory


Showing images in a directory

Reply
  #1 (permalink)  
Old 08-24-03, 05:58 AM
Bob Bob is offline
New Member
 
Join Date: Aug 2003
Location: England
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Showing images in a directory

Well I run a gaming website, and it runs off my own code. But right now I can't think of a solution for my problem.
What I have is every game in the database has a directory for it's images, and inside that directory is a directory labelled 'media'.

What I want to do is to show all the images in a directory in rows of 4. I think I could probably do the grab all the image files, but the sorting into the rows I don't know how to do.
Could anyone show me how to do this?
I hope I explained clearly enough
Reply With Quote
  #2 (permalink)  
Old 08-24-03, 09:27 PM
ermau's Avatar
ermau ermau is offline
Wannabe Coder
 
Join Date: Aug 2003
Location: Florida, USA
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
You could use a counter. Use a loop to add a new table column until teh counter reaches four, then add a new row and column then go columns until it reaches four again.

HTH, Eric.
__________________
PHP / mySQL Developer
Reply With Quote
  #3 (permalink)  
Old 08-24-03, 09:33 PM
alfreds's Avatar
alfreds alfreds is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

You are lucky, I am just working on a similar script. Here is the solution i made:

PHP Code:

Function Display_Img ($game_dir$sub_dir )  {

   
//path to directory where images are
      
$img_types = array("jpg""jpeg""png");   // image file types
      
$dir_path $game_dir "/" $sub_dir "/";   // path to image directory
      
if ($handle opendir($dir_path))  {
     while (
false !== ($file readdir($handle)))  { 
                for (
$i 0$i count($img_types); $i++)   {
                    if (
eregi("\.". $$img_types[$i] ."$"$file))  {
                
$tmp_file_path $dir_path $file;
                                       print 
"<img src='$tmp_file_path'>";
                    }
            }
    }
   
closedir($handle); 
// close if


That above, is a simple function, that runs through your GAME_DIR (starting from the location of the place where the file with this function is located) and accompanied with particular game subdir, in your case - 'media', and gets all the image file in the dir.

This function does the whole thing, except printing the result in rows. I hope you will get the idea of how to arrange them in a row, or in table!

Hope, this solved some of your problem!
Kaspars






[/PHP]

Last edited by alfreds; 08-24-03 at 10:05 PM.
Reply With Quote
  #4 (permalink)  
Old 08-25-03, 06:01 AM
Bob Bob is offline
New Member
 
Join Date: Aug 2003
Location: England
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks. With a bit of a change it worked great. It does seem to try to show two-non existant images. I'll work at getting rid of them.
Thanks for your help

Update: I managed to get rid of the two broken images. It works fine now. Thanks again for your help

Last edited by Bob; 08-25-03 at 06:17 AM.
Reply With Quote
  #5 (permalink)  
Old 08-25-03, 08:16 AM
alfreds's Avatar
alfreds alfreds is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Good, it helped.

I spent a lot of work and effort on making it for my own needs, so no prob helping you, man!

Have a great time!
Kaspars
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
i know how to delete a file! but how to delete a directory? forcer JavaScript 3 01-28-04 07:00 AM
Upload to user-defined directory? tom PHP 1 09-26-03 11:14 AM
List images and zip before download jaimexyz Script Requests 0 09-01-03 03:01 PM
WebSight Directory System v1.0 available! Stefan General Advertisements 0 07-18-03 03:00 PM
retrieve directory Greg PHP 3 06-19-03 03:10 AM


All times are GMT -5. The time now is 05:35 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.