Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2012, 08:41 AM   PM User | #1
Local Hero
New Coder

 
Join Date: May 2005
Location: Utah
Posts: 58
Thanks: 6
Thanked 0 Times in 0 Posts
Local Hero is an unknown quantity at this point
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!
Local Hero is offline   Reply With Quote
Old 11-07-2012, 12:20 PM   PM User | #2
patryk
Regular Coder

 
patryk's Avatar
 
Join Date: Oct 2012
Location: /dev/couch
Posts: 395
Thanks: 2
Thanked 64 Times in 64 Posts
patryk is on a distinguished road
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++;

patryk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:48 PM.


Advertisement
Log in to turn off these ads.