You are here: Re: Can't Escape « PHP Programming Language « IT news, forums, messages
Re: Can't Escape

Posted by Good Man on 09/11/07 21:48

Confused but working on it <PostInGroups@wherever.com> wrote in
news:2007091114413816807-PostInGroups@wherevercom:

> Hi all,
>
> I'm trying to do something simple and grabbed a snippet from the php
> manual for reading files in a directory. The snippet echos out a nice
> list of files.
> <?php
> //Open images directory
> $dir = opendir("images");
> //List files in images directory
> while (($file = readdir($dir)) !== false)
> {
> echo "filename: " . $file . "<br />";
> }
> closedir($dir);
> ?>
>
> So with my very limited PHP skillset I am trying to concatente the
> $file variable in an image tag. I can't seem to escape this the right
> way. I've done some cutting and pasting and commenting trying to
> figure this out. (keep the laughing down. :)
>
> <?php
> //NOT WORKING - shows the little blue question mark box
> echo "<img src = \"/DSC01351.jpg\">";

This means: show an image, the source of which is at the top of the
server. Perhaps you should put the entire path to the image, relative
to where your PHP script is being called from.

echo "<img src=\"path/to/my/image/DSC01351.jpg\">";




> //List files in images directory
> while (($file = readdir($dir)) !== false)
> {
> // Below Works---Shows the filename like DSC01351.jpg
> echo "filename: " . $file;
> //NOT - shows the little blue question mark box
> echo "<img src=" . $file . ">";
> //NOT - shows the little blue question mark box
> echo "<img src=\".$file.\">";
>
> }
> closedir($dir);
> ?>

according to your script, the images are located in the directory
"images". therefore, you need the directory name in addition to the
image name. should be:

echo "<img src=\"images/".$file."\" alt=\"my image\">";

etc





>
> Just amazingly frustrated with something that is so simple. I'v tried
a
> lot of ways to escape the quotes in the img tag but can't mahe it
work.
> left a couple of example...
>
> Any help would be greatly appreciated.
>
> TIA!
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация