Click to See Complete Forum and Search --> : kinda uhm sorta i dunno well like
Bungholio
06-26-2003, 03:55 PM
Hi, thanks for looking,
Ive got for example 6 images in my folder
12_force1.jpg
12_fun.jpg
13_whhaat.jpg
13_awww.jpg
14_somma.jpg
14_tune.jpg
anyways, i want a function to list the images based on the #### at the front ...
function GetPics($ID){
if $ID is in the name of the image
echo
}
that kinda thing...I know its a stupid way to do it, and something like storing in directories would make alot more sense, but ive got some crazy permission problems with this host, and dont want to get into it ... so if anyone can help with that, id reaaaally appreciate it :) :) :)
Thanks,
Al
Here's the logic:
Get the name of the image, split at the _ (if this is after the number in all the images) and take the first part. If you need help, post how you are getting the images (looping though the directory and pulling all files?).
Bungholio
06-26-2003, 08:07 PM
well i would prefer to not have to arrray all the files and then sort thru them, cause it'd be quite slow ... just thought maybe PHP has something like that already ... if not maybe i can think of a different way ... i dunno
Originally posted by Bungholio
well i would prefer to not have to arrray all the files and then sort thru them, cause it'd be quite slow ...
Perhaps you misunderstood what pyro said:
Originally posted by pyro
If you need help, post how you are getting the images (looping though the directory and pulling all files?).
Notice the phrase in the parenthesis. What he's saying is, read the contents (files) of the directory, and fill them into an array automatically, then loop through each one and split it at the underscore (_); and return the two characters (digits) before it.
Just a BTW thing, pyro, is there an alternate way to use split? Normally I use the list() function like this:
$str = "abc_cba";
list($a, $b) = split("_", $str);
echo ("$a<br>\n$b");
[Jona]
Jona -
Yeah, you can do something like this, though using list is fine.
<?PHP
$img = "10_image.gif";
$array = split("_",$img); #will turn $array into an array of the split items.
echo $array[0];
?>
Bungholio -
You can use a script like this to get all the files out of the directory, and then use something like the above to split it up...
$handle = opendir($folder); #opens the directory so we can read the files out
while ($file = readdir($handle)) { #loop through the files
$array[] = $file; #make an array of the files
}
closedir($handle); #close the directory