Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

any php gurus?

Thread Tools
 
Search this Thread
 
Old 03 July 2006, 10:10 AM
  #1  
ChefDude
Scooby Regular
Thread Starter
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default any php gurus?

i want a script to enumerate through the files in a sub directory

I know it'll be 10 lines of code, so
sorry, i'm a little dense on this, i'm an asp boy <embarrassed>


help appreciated
CD
Old 03 July 2006, 11:49 AM
  #2  
RichB
Scooby Regular
 
RichB's Avatar
 
Join Date: Apr 1999
Location: Bore Knee Muff
Posts: 3,666
Likes: 0
Received 0 Likes on 0 Posts
Default

In it most basic form this will show you all the images in your current folder:

<html>
<body>
<?php
$d = dir(".");
$count=1;
while (false !== ($entry = $d->read())) {
$lowname=strtolower($entry);
$pos1 = strpos($lowname, '.jpg');$pos2 = strpos($lowname, '.gif');$pos3 = strpos($lowname, '.png');$pos4 = strpos($lowname, '.bmp');
if ($pos1 == true || $pos2 == true || $pos3 == true|| $pos4 == true) {
echo '<p><img src="'.$entry.'"/></p>';
}
}
$d->close();?>
</body>
</html>
Old 03 July 2006, 01:15 PM
  #3  
ChefDude
Scooby Regular
Thread Starter
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

thanks
Old 03 July 2006, 01:40 PM
  #4  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Default

I'd use preg_match and a case-insensitive regex like /\.(png|gif|jpe?g|bmp)$/i and save on those horrible if statements and temporary variables
Old 03 July 2006, 01:50 PM
  #5  
ChefDude
Scooby Regular
Thread Starter
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

ok, can i have some sample code then?

how do i do a querystring, eg; www.page.com?variable=image_name
Old 03 July 2006, 02:15 PM
  #6  
ChefDude
Scooby Regular
Thread Starter
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

did it!!!


http://www.z3romass.com/usr/egypt2006/mt/fid.php

never coded php before :|
Old 04 July 2006, 12:41 AM
  #7  
RichB
Scooby Regular
 
RichB's Avatar
 
Join Date: Apr 1999
Location: Bore Knee Muff
Posts: 3,666
Likes: 0
Received 0 Likes on 0 Posts
Default

yeah, that code does suck but Chef didnt say exactly what he wanted to do with each file, I just used that as an example ... but I never did bother to get the hang of regular expressions though ... lol

Trending Topics

Old 04 July 2006, 09:23 AM
  #8  
ChefDude
Scooby Regular
Thread Starter
 
ChefDude's Avatar
 
Join Date: Aug 2005
Posts: 4,290
Likes: 0
Received 0 Likes on 0 Posts
Default

the code works Rich, i just needed to enumerate through thumbnail image files to present a gallery page. sorted, thanks




All times are GMT +1. The time now is 06:47 PM.