|
Posted by Rik Wasmus on 09/16/07 21:58
On Sun, 16 Sep 2007 23:36:49 +0200, Confused but working on it =
<PostInGroups@wherever.com> wrote:
> So I've been trying to get a bit of code to:
> Read all of the files in a dir called thumbs, but not the . and .., us=
e =
> the filename in a link to get the same filename in an images dir. Now =
=
> I'm trying to use a foreach and glob as suggested, and get rid of the =
=
> part of the string that has the dir info. SO the below produces all my=
=
> thumbs nicely and all are links.
>
> <?php
> foreach (glob("thumbs/*.jpg") as $file)
> {
> str_replace('thumbs/', '', $file);
This does NOT alter $file. $file is not taken as a reference and altered=
=
inside str_replace();
$file =3D str_replace('thumbs/', '', $file);
> echo "<a href=3D'images/$file'><img src=3D'$file' class=3D\"pad1em=
\"></a>";
> }
> ?>
>
> But why doesn't the sring manipulatioon not work? I'm very grateful fo=
r =
> the line with the str_replace. If i remove the braces above i get the =
=
> last thumb and a bad link. Replace braces and I get all my thumbs. But=
=
> the link still has thumbs/ in it.
>
> hmmm.
>
> thx..ron
Why do your images live in a thumbs dir and you still want an '/images/'=
=
link?
However, this may help you:
<?php
foreach (glob("thumbs/*.jpg") as $file){
$filename =3D basename($file);
echo "<a href=3D'images/$filename'><img src=3D'$filename' =
class=3D'pad1em'></a>";
}
?>
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|