Results 1 to 5 of 5

Thread: [PHP] Dir Help

  1. #1
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default [PHP] Dir Help

    Hey,

    I have just designed this script, there is a folder with 10 images in it...

    01.jpg
    01t.jpg
    02.jpg
    02t.jpg ect... all the way to 05.jpg

    I want it to display 4 images per div, so it should echo 4 images in 1 div then 1 image in another div because I DONT want the script to display the images with t in it so it will NOT display 01t.jpg ect...

    Can you help me fix my code so it doesnt take into account the images with a t in the name.

    PHP Code:
    <?php


    $image_dir 
    "";

    /* settings */
    $per_column 4;
            
            
    /* step one:  read directory, make array of files */
    if ($handle opendir($image_dir)) {
    while (
    false !== ($file readdir($handle))) 
    {
    if (
    $file != '.' && $file != '..'
    {
    $files[] = $file;
    }
    }
    closedir($handle);
    }
            
    /* step two: loop through, format gallery */
    if(count($files)){
    echo 
    "<div>";
    foreach(
    $files as $file){
    $count++;
    echo 
    '
    <span><img width="44" height="44" src="'
    $image_dir''$file'" alt="#" /></span>
    '
    ;

    if(
    $count $per_column == 0) { echo '</div>'; }
    }}
    else
    {
    echo 
    ''// Error no images
    }
    echo 
    "";
    }
    ?>
    Dan =)


  2. #2
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    Sorry, I mean I want the script to only show images with a t and not show images without a t in it =)


  3. #3
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    Tbh theres probs an easier way than what I'm gonna say but you could use str_replace and create a new var and replace t with x or something and then check if the original file is equal with the new str replaced file

  4. #4
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    Ok....

    You have lost me!

    What I was thinking is a little bit of script that will say if the file has a t in it continue if not skip?

    Dan


  5. #5
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    Fixed, Thanks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •