
June 25th, 2012, 02:04 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 1
Time spent in forums: 43 m 17 sec
Reputation Power: 0
|
|
|
General - Php code help
I have over 5000 files in a directory. and if they contain "-XXX.jpg" I want to do something with them.
The below code.. kind of works but not quite accurately.
is there any easier way .. a way that will definitely work.
$array = Array(
0 => '-1.jpg',
1 => '-2.jpg',
2 => '-3.jpg',
3 => '-4.jpg',
4 => '-5.jpg',
5 => '-6.jpg',
6 => '-7.jpg',
7 => '-8.jpg',
8 => '-9.jpg',
9 => '-10.jpg',
10 => '-11.jpg',
11 => '-12.jpg',
12 => '-13.jpg',
13 => '-14.jpg',
14 => '-15.jpg',
15 => '-16.jpg',
16 => '-17.jpg',
17 => '-18.jpg',
18 => '-19.jpg',
19 => '-20.jpg',
20 => '-30.jpg'
);
if ($handle = opendir('/skin-batcher/omgz')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filename = '/skin-batcher/omgz/$file';
$id = time( ); // filename
foreach ( $array as $needle ) {
if (strpos($file,$needle) !== false) {
echo $file;
}
}
}
}
closedir($handle);
}
?>
|