|
Posted by Confused but working on it on 09/16/07 20:59
On 2007-09-16 10:05:28 -0700, gordonb.uwl0i@burditt.org (Gordon Burditt) said:
>>> str_replace('thumbs/', '', $file);
>>
>> I put this right above my echo and did get an image. But only one. It
>> was the last file in the directory. Also tried to replace $file within
>> my output line but failed.
>> Maybe my coffee hasn't kicked in.
>
> After you added the str_replace() call, is the echo INSIDE or OUTSIDE
> of the foreach() loop?
>
> What do you need to have after foreach() to ensure that the following
> TWO statements are inside the loop?
>
> Although you can get advice here, don't expect it to be click-by-click,
> keystroke-by-keystroke instructions.
Now that's a good lead. In my attempts using readdir it would read then
echo, read then echo. I'm learning a bit as I go and having a bit of
fun. Here are a few things that work:
<?php
echo "Example glob<br>";
foreach (glob("thumbs/*.jpg") as $file)
echo "<a href='images/$file'><img src='$file' class=\"pad1em\"></a>";
?>
This works meaning it doesn't fail until I click the link. Will get
back to a couple things I've tried.
Here are two more samples. They look exactly the same but in the same
page example 1 gives me the image marker for the thumb and the link to
the larger picture works. Example 2 shows the thumb and the link works.
I see no difference in the code. These do what I want
<?php
echo "<br>Example while readdir 1<br>";
//Open images directory
$dir = opendir("thumbs");
//read files in the dir
while(($file = readdir($dir)) !== false)
//test to make sure jpg
if(eregi("\.jpg",$file))
{
echo "<a href='images/$file'><img src='$file' class=\"pad1em\"></a>";
}
closedir($dir);
?>
<?php
echo "<br> Example - while readdir 2<br>";
//Open images directory
$dir = opendir("thumbs");
//read files in the dir
while (($file = readdir($dir)) !== false)
//test to make sure jpg
if (eregi("\.jpg",$file))
{
echo "<a href='images/$file'><img src='thumbs/$file'
class=\"pad1em\"></a>";
}
closedir($dir);
?>
These do what I want which is a thumb linking to a larger picture.This
doesn't leave the intended result of file sort order when I upload.
Still accomplishes 90% of what I'm looking for.
Back to making the glob example work. You say is that bit of code
inside or outside the foreach loop. Doesn't it "foreach" until it'
done? By the example above it does. So when I said I put my line in
between the foreach line and my echo line that's what I meant. This
gives me one thumb that still has the images in the link:
<?php
echo "Example glob<br>";
foreach (glob("thumbs/*.jpg") as $file)
str_replace('thumbs/', '', $file);
echo "<a href='images/$file'><img src='$file' class=\"pad1em\"></a>";
?>
Removing the semi in the str_replace line gives me an error on the echo
line. So if you really mean insie I did this:
<?php
echo "Example glob<br>";
foreach ((glob("thumbs/*.jpg") as $file)
str_replace('thumbs/', '', $file);)
echo "<a href='images/$file'><img src='$file' class=\"pad1em\"></a>";
?>
This gives me a parse error on the foreach line. I tried a bunch of
different ways all the way to:
<?php
echo "Example glob<br>";
foreach (glob("thumbs/*.jpg") as str_replace('thumbs/', '', $file))
echo "<a href='images/$file'><img src='$file' class=\"pad1em\"></a>";
?>
This error is a bit different - Parse error: parse error, expecting
`T_VARIABLE' or `'$'' i
This is all I've tried so far. Will post back if I get it.
thx..ron
[Back to original message]
|