|
Posted by Krustov on 09/21/07 22:05
<comp.lang.php>
<Steve>
<Fri, 21 Sep 2007 16:44:35 -0500>
<SWWIi.124$4v3.54@newsfe12.lga>
> > (stuckle and his lapdogs are forbidden from replying to this thread as i
> > dont actually want any help from them)
>
> hope i'm not one of them
Nah - when the xargs take over planet earth - your name will be on the
protected list :-)
> <?
> function listFiles($path = '.', $extension = array(), $combine = false)
> {
> $wd = getcwd();
> $path .= substr($path, -1) != '/' ? '/' : '';
> if (!chdir($path)){ return array(); }
> if (!$extension){ $extension = array('*'); }
> if (!is_array($extension)){ $extension = array($extension); }
> $extensions = '*.{' . implode(',', $extension) . '}';
> $files = glob($extensions, GLOB_BRACE);
> chdir($wd);
> if (!$files){ return array(); }
> $list = array();
> foreach ($files as $file)
> {
> $list[] = ($combine ? $path : '') . $file;
> }
> return $list;
> }
> function getImages($value, $key, &$images)
> {
> $pathInfo = pathinfo($value);
> $path = $pathInfo['dirname'];
> $fileName = $pathInfo['basename'];
> $fileNumber = 0;
> $matches = array();
> if (preg_match("/^([^_]*?)_(\d+).*$/", $fileName, $matches))
> {
> $fileName = $matches[1];
> $fileNumber = max($images[1][$path][$fileName], $matches[2]);
> }
> $images[1][$path][$fileName] = $fileNumber;
> }
> $files = listFiles('zimages_background', null, true);
> $images = array();
> $imageList = array('', &$images);
> array_walk($files, 'getImages', $imageList);
> foreach ($images as $path => $files)
> {
> foreach ($files as $name => $version)
> {
> echo '<pre>============================</pre>';
> echo '<pre>path :: ' . $path . '</pre>';
> echo '<pre>file :: ' . $name . '</pre>';
> echo '<pre>version :: ' . $version . '</pre>';
> }
> }
> ?>
I did it using the following , But there must be a better and/or easier
way of doing it .
<?php
$batman=1;
$dir="zimages_background/";
$joker=opendir($dir);
while (false!==($boywonder=readdir($joker)))
{
$ripper=substr($boywonder,0,11);
$pizza=1;
if ($boywonder==".") {$pizza=0;}
if ($boywonder=="..") {$pizza=0;}
if ($ripper<>"background_") {$pizza=0;}
if ($pizza==1) {$files[$batman]=$boywonder; $batman=$batman+1;}
}
closedir($joker);
$joker=1;
while ($joker<$batman)
{
$temp1=($files[$joker]);
$temp2=strlen($temp1);
$temp3=substr($temp1,$temp2-4,4);
$temp4=str_replace("background_","",$temp1);
$temp4=str_replace(".jpg","",$temp4);
$temp4=str_replace(".png","",$temp4);
$temp4=str_replace(".gif","",$temp4);
$cake[$temp4]=$temp3;
$joker=$joker+1;
}
$batman=$batman-1;
?>
--
(c) The Amazing Krustov
Navigation:
[Reply to this message]
|