SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would be the best way of displaying ANY images with the extension "tmb.gif" or "tmb.jpg" on a page using PHP?

    I would also need to link to the fullsize file which would have the same name minus the tmb part.

    Has this been done or am I reinventing the wheel?

    How do I step through each file in a directory?

  2. #2
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should do it -- check out php.net/readdir for more help on directories.. good luck

    PHP Code:
    <?

    function GetDirArray($somePath)
    {
      
    $handle=opendir($somePath);   
      while (
    $file readdir($handle))
      {
        if (
    $file != "." && $file != "..")
        {
          
    $tail substr($file, -7);
          if (
    $tail == "tmb.jpg" || $tail == "tmb.gif")
            
    $retVal[count($retVal)] = $file
        }
      }
      
      
    closedir($handle);
      
    sort($retVal); 
      return 
    $retVal;
    }
     

    $images GetDirArray(".");

    while (list(
    $key$val) = each($images))
    {
       
    $actual_img substr($val,0,-7) . substr($val,-4);
       echo 
    "<a href=\"$actual_img\"><img src=\"$val\"></a> (" filesize($actual_img) . " bytes)<br>\n";
    }
      
    ?>
    Last edited by cokeman; Apr 12, 2001 at 11:49.

  3. #3
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man! That's much appreciated but I get the following errors.....

    Warning: Wrong datatype in sort() call in c:\phpdev3\www\sportsgamer\images\news\stories\33\images.php on line 18

    Warning: Variable passed to each() is not an array or object in c:\phpdev3\www\sportsgamer\images\news\stories\33\images.php on line 25

    18 = sort($retVal);
    25 = while (list($key, $val) = each($images))

    Any ideas?

  4. #4
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOPS! My bad!

    Turns out that when I ran the script, I didn't have any tmb.gif or tmb.jpg files in the directory.

    BAH!

    Thanks man, working a treat.

  5. #5
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great..


Bookmarks

Posting Permissions

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