Jump to content

Read directory and display images.


perficut

Recommended Posts

I would like to create a .php file that will look in the current diectory for any images and then display them in a 200x200 format.  Layout can be simple, perhaps 4 or 5 pictures per row, and how ever many rowes are needed based on the number of pictures. The images will be named starting at 1.jpg up to an undetermined number. In some cases as many as 20 images. But each project we do will dictate the number of pictures uploaded.

 

What I want to be able to do, is simply, delete all .jpg files in the directory, then upload all the new ones, everytime we work a new project.  The php file will do the rest.  The only images in the directory will be those for the project under way.  When we finish the project the image files will remain, until a new project begins.

 

 

Can anyone get me started on the code for this .php file?

 

Link to comment
Share on other sites

Just to let you know, we will not code this for you. 

 

Now that we're past that, you can use glob() to look for the files.  Will they always be .jpg, because that would make it easy. xD

 

Something like:

 

$count = 0;

foreach (glob("*.jpg") as $pic) {

      printf('<img src="%s" width="200" height="200" />', $pic);

      $count++;

      if ($count % 5 == 0) {

              echo "<br />";

      }

}

Link to comment
Share on other sites

Darkwater;

 

1. Yes they will always be .jpg files.

2. I wouldnt expect anyone to code the file, just get me started.

3. I'm new to php, have some old pascal, basic, c++ coding from a long time ago, so understanding code is not difficult for me. However, its been a long time, and of course I am trying to teach myself.

 

What ou have provided is a great start. I will try to work with that and see what I can come up with.  If anyone else has any tips, please feel free.

 

Thank you! everyone.  This is an invaluable forum and you guys have always helped me when I needed it.  I only wish I could repay the favors.

 

Link to comment
Share on other sites

You could also record images uploaded in a database. Then just do a mysql query for all images(or just the ones you want) and then

 

$n = 0;

while($row = mysql_fetch_assoc($result))

{

  extract($row);

  echo "<img src=$image_file_location height=200 width=200>";

  $n++;

  if($n == 5)

  {

    echo "<br>\n";

    $n = 0;

  }

 

}

 

something like that

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.