Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    My PHP gallery not working, problem with explode.

    Ok so I made a gallery script in PHP and it worked, but I wanted to customize it even more so it presents name, size (width and height) and filetype based on image name (easy updating).
    Well here's the code:

    PHP Code:
    <?php
        $count 
    0;
        if (
    $handle opendir('sub/portfolio/abstract'))
            {
            while (
    false!== ($file readdir($handle)))
                {
                if (
    $file!= "." && $file!= "..")
                    {
                    
    $fileexp = (explode("_",$file));
                    echo 
    "<td align=\"center\"><a href=\"sub/portfolio/abstract/$file\"><img src=\"sub/portfolio/abstract/$file\" width=\"100\" height=\"100\" border=\"0\"></a><br />Name: $file[0]<br />Size: $fileexp[1]<br />Type: $fileexp[2]<br></td>";
                    
    $count $count +1;
                    if (
    $count == 4)
                        {
                        echo 
    "</tr><tr><td colspan=\"4\" style=\"background-color: #8b1300; height: 1px; border-top: 1px solid #ff2300; border-bottom: 1px solid #360700;\"></td></tr><tr>";
                        
    $count 0;
                        }
                    }
                }
            echo 
    "</table>";
            
    closedir($handle);
        } 
    ?>
    It explodes and works however the first returned array piece breaks at a place that I don't want.

    If the pictures name is: Miracle of Birth_1280x1024_.jpg
    it returns:

    Name: M
    Size: 1280x1024
    Type: .jpg

    There, the name is wrong and I don't know why since it should only break it up when it meets an underscore.

    I could easily have just missed something, but I can't find it.

    /Tobias
    Last edited by tobiassjondin; 05-11-2008 at 05:31 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    It is exploding properly, you have to use the 'exploded' array not the original variable.

    Name: $file[0] should be Name: $fileexp[0]

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is exploding properly, you have to use the 'exploded' array not the original variable.

    Name: $file[0] should be Name: $fileexp[0]
    Christ, well that seems quite reasonable what a miss. thanks mate.


  •  

    Posting Permissions

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