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 2 of 2
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    65
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Search for files - preg_match

    I have code that saves images to a directory based on the last 5 digits of the session ID. So I have a list of images 12345-hello.jpg, 12345-goodbye.jpg, 54321-adios.png, etc.

    I have a script to display the files, but there are a lot of images to load. If I only want to see the files from "12345", I would like to have the PHP display only those files.

    My code to get the images:
    PHP Code:
    <?php $files glob("uploaded/*.*"); for ($i=0$i<count($files); $i++) {$num $files[$i];print $num."<br />";echo '"<a href="'.$num.'"><img width=500 src="'.$num.'" alt="" />'."<br /><br /></a>"; } ?>
    I think I have to use PREG_MATCH, but as simple as looking for files is, it was tough for me to get to this point.

    Can I get a little bump over the hill so I can search for just a string that I can input?
    Thanks!

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    how about something like that:
    PHP Code:
    $id 12345;
    $files glob('uploads/' $id '-.*');
    $i=0;
    while(isset(
    $files[$i])){
        
    $mime mime_content_type($files[$i]);
        if(
    $mime == 'image/png' || $mime == 'image/jpeg' || $mime == 'image/gif' || $mime == 'image/bmp'){
            
            
    //do omething with $files[$i]
        
    }
        
    $i++;



  •  

    Posting Permissions

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