How do I echo a .png image to the browser?

images php coding issues or problems here.

Moderators: macek, egami, gesf

BrianSchmit
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Feb 29, 2012 1:49 pm

How do I echo a .png image to the browser?

Postby BrianSchmit » Wed Feb 29, 2012 2:30 pm

I am a newbie to .php

I have an html form, when the user clicks submit, the .php form handler needs to post an image to the posted back html document. I have hard coded the file path as a variable but I get a broken image icon. (.img)

here is my code from the php file:
//process.php

Code: Select all

<html><body>
<?php
//$item = $_POST['item'];
$item ="2010";
$url = "C:\wamp\www\FORM PROCESSING\Climate_Images\Portland Climate Summary for Year " . $item .".png";
echo "<img src=\"$url\""; 
?>


I am using WAMP for dev on localhost. Just wondering if I need to do something to config the mime types or if maybe my php syntax is incorrect?

Thank You , Brian

User avatar
L33R
New php-forum User
New php-forum User
Posts: 133
Joined: Fri Dec 30, 2011 4:27 am
Location: Liverpool

Re: How do I echo a .png image to the browser?

Postby L33R » Wed Feb 29, 2012 8:32 pm

Its a webserver where your images are stored. <img src =" takes a URL or relative location" />

Code: Select all

   // a link to my image
   $url="http://localhost/sandbox/images/film-cult.png";
   echo "<img src={$url} />";


   // this should work for yours.
   $url = "http://localhost/FORM PROCESSING/Climate_Images/Portland Climate Summary for Year " . $item .".png";
   echo "<img src={$url} />"; 


for fiture reference if you need to use a backslash in a string variable you need to add it twice to escape it \\.


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest

cron