sanainfotech
sanainfotech

Reputation: 691

display image from server embedding php in html

echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />";

How can i embed above PHP code in html. i have image folder in server where i would like to display image.

Upvotes: 1

Views: 3693

Answers (5)

Pupil
Pupil

Reputation: 23968

You can embed PHP inside HTML also, you can embed HTML inside your PHP. Both approaches work. But, preferred on is to embed PHP inside HTML. The reason is:

1) PHP parser parses every PHP code.

2) So, if we have written HTML code in PHP, it will parse the code.

3) Hence the load on parser will be more.

4) Where as, HTML tags (codes) as shown directly on the browser (without any parsing)

So always, embedding PHP into HTML is better.

Thanks.

Upvotes: 0

Pupil
Pupil

Reputation: 23968

You can try this:

<img src="images/<?php print $row['filename'];?>" alt="" /><br />

Upvotes: 1

Chetana Kestikar
Chetana Kestikar

Reputation: 570

You can also try this:

<img src="<?php echo $row['filename'];?>"/><br/>

Upvotes: 2

Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

Try this-

echo "<img src='images". $row['filename']."'  alt=''/><br />";

Upvotes: 0

Norbert Pisz
Norbert Pisz

Reputation: 3440

What's the problem?

But your file must be .php and then insert into html.

<?php echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br />"; ?>

Upvotes: 1

Related Questions