/    Sign up×
Community /Pin to ProfileBookmark

php img syntax not rigth?

Hi,

i am trying to upload my image stored the server following this tutorial online, [url]http://php.about.com/od/phpwithmysql/ss/Upload_file_sql_4.htm[/url]
they have used a while loop but i’ve used a foreach loop instead.

Essentially, i’m having trouble with the syntax of my img tag when i try to echo out the image:

[CODE]
<?php foreach ($employees as $employee): ?>
<?php echo “‘<img src=C:wampwwwimages’ . $employee[‘photo’] > ;?>” <br >

<?php endforeach; ?>

[/CODE]

I belive it has something to do with my ‘ ‘ single or ” ” double quotes, but i n can’t really point my finger to it as i get the following error:

Parse error: parse error, expecting `T_STRING’ or `T_VARIABLE’ or `T_NUM_STRING’ in C:wampwwwemployeedisplay.html.php on line 15

line 15 is the <?php echo …….. ?> code.
Can somebody tell me if i need to close somethnig or adjust my quotes pls.

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJun 04.2010 — try

[CODE]
<?php
echo '<img src="C:wampwwwimages'.$employee['photo'].'" >' ;
?>
[/CODE]
Copy linkTweet thisAlerts:
@MindzaiJun 04.2010 — You will also either want to use a standard URI in the src attribute, or else use the file URI scheme.

[code=php]echo '<img src="/images/'.$employee['photo'].'" >';[/code]
Copy linkTweet thisAlerts:
@tirnaJun 04.2010 — try


&lt;?php
echo '&lt;img src="C:wampwwwimages'.$employee['photo'].'" &gt;' ;
?&gt;
[/quote]


using a uri like in <img src="C:WindowsTemppic1.jpg" alt="" /> is valid if opening a html page on a local pc.
Copy linkTweet thisAlerts:
@MindzaiJun 04.2010 — It might work OK in your browser, but it is not a URI, and the specs state that the src attribute requires a URI.
Copy linkTweet thisAlerts:
@tirnaJun 04.2010 — was clarifying because there might be newbies not aware of it.

and if your only running a web page on a local pc it will work regardless of the spec.

but if running it on a server then obviously you need a valid uri.
Copy linkTweet thisAlerts:
@MindzaiJun 04.2010 — See my edit above.
Copy linkTweet thisAlerts:
@tirnaJun 04.2010 — not sure who you're talking to - me or the OP ?

if it's me, I haven't got time at the moment - helping someone with something more important.
Copy linkTweet thisAlerts:
@MindzaiJun 04.2010 — The spec doesn't magically change if you are running on a local server as opposed to remote :rolleyes:. Open an HTML file with firefox - do you see the file path in the location bar, or do you see a URI using the file scheme? Like I said, it might work in your client, but that doesn't make it correct. You can either hack together programs based on exploiting non-standard features, or you can just do it right. If you prefer the former be my guest.
Copy linkTweet thisAlerts:
@tirnaJun 04.2010 — this code

[code=php]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>

<p>
<img src="C:WindowsTemppic1.jpg" alt="" />
</p>

</body>
</html>
[/code]


displays as in the attached jpg screen dump when I open the html file on my [B]local pc[/B] as I described earlier. I did not mention at any server - local or otherwise.

I'm not going to waste anymore time discussing this as I'd be surprised if you didn't agree there are much more important things going on in our world for me to spend time on.

If you still don't understand the point I was making earlier, hopefully someone else can help you.

[upl-file uuid=1fb864ae-679a-4975-ae35-a8a5755e1cce size=21kB]wd_1.jpg[/upl-file]
Copy linkTweet thisAlerts:
@MindzaiJun 04.2010 — I don't know if you are not reading what I am saying, or if you just generally don't understand what a URI or a specification is. As I said, the (X)HTML specs state that the src attribute requires a URI, therefor although a file system path may work in your particular client, it is not correct according to the spec. This fact doesn't change depending on whether you open the file directly, run it on a local server, or run it on a remote server. I can't really put it any clearer, if you don't understand it you can either read up or keep relying on unsupported behaviour, frankly I couldn't care less which you chose ?
×

Success!

Help @nvidia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...