469,647 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

file extention - wildcard

I have the following list of image files .

When searching the latest (numbered file) in this particular case its
background_4.*** and its a .jpg file - but - the latest file in the list
could also be a .gif file at times .

zimages_background/background_1.jpg
zimages_background/background_2.jpg
zimages_background/background_3.gif
zimages_background/background_4.jpg

etc etc

How do i do a wildcard file extention search to find the latest numbered
image - regardless if its a .jpg or .gif .

I know how to search for the _* number in the filename & its how to do a
file extention wildcard search i need .
--
(stuckle and his lapdogs are forbidden from replying to this thread as i
dont actually want any help from them)
Sep 21 '07 #1
5 2905

"Krustov" <me@privacy.netwrote in message
news:MP************************@news.newsreader.co m...
>I have the following list of image files .

When searching the latest (numbered file) in this particular case its
background_4.*** and its a .jpg file - but - the latest file in the list
could also be a .gif file at times .

zimages_background/background_1.jpg
zimages_background/background_2.jpg
zimages_background/background_3.gif
zimages_background/background_4.jpg

etc etc

How do i do a wildcard file extention search to find the latest numbered
image - regardless if its a .jpg or .gif .

I know how to search for the _* number in the filename & its how to do a
file extention wildcard search i need .
--
(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...not sure of my association with the lapdogs. if
you mean republican, i tend to go that way on fiscal and domestic policy,
however r's look more d than d's do these days. if you only mean mentally
entrenched to blindly follow...i can assure you i'm not. ;^)

here's a flexible function to list files and one to return the file number,
followed by an example with your data above. if the image doesn't meet
image_number.ext, then the whole file name is returned and the version
number will be zero.

hth,

me

========================
<?
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>';
}
}
?>
Sep 21 '07 #2
<comp.lang.php>
<Steve>
<Fri, 21 Sep 2007 16:44:35 -0500>
<SW**************@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
Sep 21 '07 #3
><?
>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 .
not really. if the below works for you, that's what you need to use i
suppose. what i did above is a bit more lenient. it doesn't care what the
file name is or in what directory you are looking or what extention a file
has (it automatically screens out other images like .tif, etc.). i usually
try to build around the concept of what i'm going for rather than
pigeon-hole-ing myself into maintaining code - say, if i started using other
types of images in this case.

like i said. if the below works, go for it.

cheers.
>
<?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

Sep 22 '07 #4
<comp.lang.php>
<Steve>
<Fri, 21 Sep 2007 19:25:01 -0500>
<kh************@newsfe02.lga>
I did it using the following , But there must be a better and/or easier
way of doing it .

not really. if the below works for you, that's what you need to use i
suppose. what i did above is a bit more lenient. it doesn't care what the
file name is or in what directory you are looking or what extention a file
has (it automatically screens out other images like .tif, etc.). i usually
try to build around the concept of what i'm going for rather than
pigeon-hole-ing myself into maintaining code - say, if i started using other
types of images in this case.

like i said. if the below works, go for it.
www.vhit.co.uk/images/steve.jpg

Its nowt important as its only a guestbook i'm writing .

There was no way for you to know this - but a user would need to ftp and
upload into the correct folder to screw things up .

I figure most newbie users who install and use this sort of thing will
only ever use the web interface .
--
(c) The Amazing Krustov
Sep 22 '07 #5

"Krustov" <me@privacy.netwrote in message
news:MP************************@news.newsreader.co m...
<comp.lang.php>
<Steve>
<Fri, 21 Sep 2007 19:25:01 -0500>
<kh************@newsfe02.lga>
I did it using the following , But there must be a better and/or easier
way of doing it .

not really. if the below works for you, that's what you need to use i
suppose. what i did above is a bit more lenient. it doesn't care what the
file name is or in what directory you are looking or what extention a
file
has (it automatically screens out other images like .tif, etc.). i
usually
try to build around the concept of what i'm going for rather than
pigeon-hole-ing myself into maintaining code - say, if i started using
other
types of images in this case.

like i said. if the below works, go for it.

www.vhit.co.uk/images/steve.jpg

Its nowt important as its only a guestbook i'm writing .

There was no way for you to know this - but a user would need to ftp and
upload into the correct folder to screw things up .

I figure most newbie users who install and use this sort of thing will
only ever use the web interface .
probably true. looks good.

best to you,

me
Sep 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Kim Jensen | last post: by
2 posts views Thread by Keith | last post: by
6 posts views Thread by JD | last post: by
2 posts views Thread by ghighi | last post: by
17 posts views Thread by Peter Duniho | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.