+ Reply to Thread
Results 1 to 2 of 2

Thread: PHP Script to Load images from a Folder but Excluding some images using Wildcard

  1. #1
    johnnygaddaar.cs58 is offline x10Hosting Member johnnygaddaar.cs58 is an unknown quantity at this point
    Join Date
    Jul 2010
    Posts
    21

    Question PHP Script to Load images from a Folder but Excluding some images using Wildcard

    Hello,

    I am using TILTVIEWER in my Website for displaying my Photo Gallery Images in a Flash View here http://www.clan-icsl.com/images/photoalbum/

    Actually my Photo Gallery stores all Thumbnail and Enlarged images in a single folder. And I want to display only the enlarged images.

    So using the code given below, I am able to GET all the images.

    But, I am unable to exclude particular images, i.e, Thumb images as *_t1.jpg and *_t2.jpg where t1 and t2 refers to Thumbnail 1 and 2 of the Enlarged images.

    So please help me to edit this code to get my problem resolved.

    <?php
    echo "<tiltviewergallery>
    <photos>";
    $files = glob("*/*.jpg");
    for ($i=1; $i<count($files); $i++)
    {
    $num = $files[$i];
    echo '<photo imageurl="'.$num.'" linkurl="http://www.google.com">
    <title>Image 1</title>
    <description>This is a regular text description.</description>
    </photo>';
    }
    echo '</photos>
    </tiltviewergallery>';
    ?>

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP Script to Load images from a Folder but Excluding some images using Wildcard

    Note: you can use [php], [html] or [code] tags (as appropriate) to preserve formatting and (in some cases) get colorized code.

    glob patterns don't offer a way of excluding files, but if the files you want to include , you might be able to use a more specific pattern (e.g. only the files you want end with '_f.jpg', so you use a pattern of '*_f.jpg'). You can filter out the entries using array_filter, preg_grep, or within your loop:

    PHP Code:
    <?php
    // <= PHP 5.2
    $files array_filter(glob("*/*.jpg"), 
        
    create_function('$name''return ! preg_match("/_t[12]\.jpg$/", $name);'));
    // >= PHP 5.3
    $files array_filter(glob("*/*.jpg"), 
        function(
    $name) { return ! preg_match('/_t[12]\.jpg$/'$name);});

    // or
    $files preg_grep('/_t[12]\.jpg$/'glob("*/*.jpg"), PREG_GREP_INVERT);

    // or
    foreach (glob("*/*.jpg") as $file) {
      if (! 
    preg_match('/_t[12]\.jpg$/'$file)) {
        
    ?>
        <photo imageurl="<?php echo $file?>" linkurl="http://www.google.com">
          <title>Image 1</title>
          <description>This is a regular text description.</description>
        </photo>
        <?php
      
    }
    }
    Another, simpler approach is to separate thumbnails from full images, storing each in separate directories. If you create a "thumbs" subfolder in each image folder, you wouldn't even have to change your glob pattern.
    Last edited by misson; 08-01-2010 at 03:18 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. I just parked a domain, images don't load anymore
    By apbios in forum Free Hosting
    Replies: 1
    Last Post: 06-08-2008, 12:54 PM
  2. Images only allowed in image folder?
    By DarkArcher in forum Free Hosting
    Replies: 1
    Last Post: 03-19-2008, 07:53 PM
  3. Errors with 2/3 server status load images
    By McPhee in forum Free Hosting
    Replies: 0
    Last Post: 01-23-2008, 12:12 PM
  4. Images won't load on addon-domain (may need admin support)
    By IonCannon218 in forum Free Hosting
    Replies: 2
    Last Post: 12-14-2007, 07:35 PM
  5. Corrupted Images or No Images at all!
    By kcchan in forum Free Hosting
    Replies: 8
    Last Post: 11-03-2007, 07:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers