Entry
PHP: Internet: Web: Server: Image: How to send an image from the web server to web browser client?
Mar 14th, 2005 04:50
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 14 March 2005 - 05:28 pm ----------------------
PHP: Internet: Web: Server: Image: How to send an image from the web
server to web browser client?
Use the MIME type to inform the browser about what
is going to be send.
---
Steps: Overview:
1. -Before you send the image, print the text:
Content-type: <your text type>
---
e.g.
Content-type: text/html
---
e.g.
Content-type: image/gif
---
e.g.
Content-type: image/jpeg
---
e.g.
Content-type: image/png
---
e.g.
Content-type: image/vnd.wap.wbmp
---
---
2 methods to display the image file in your web browser:
1. use the filename as the source (SRC) in an <IMG> tag
2. display the content of the filename
---
---
Method: use the filename as the source (SRC) in an <IMG> tag.
--- cut here: begin --------------------------------------------------
<?php
// shows a picture via printing HTML code
$filenameS = 'fotoknud.jpg';
header( "Content-type: text/html" );
print '<IMG SRC=' . "'" . $filenameS . "'" . ' ' . 'WIDTH=180 HEIGHT
=150 ISMAP ALT=' . "'" . '[picture: knud]' . "'" . '>';
?>
--- cut here: end ----------------------------------------------------
---
---
Method: display the content of the filename
--- cut here: begin --------------------------------------------------
<?php
// only shows the picture
$filenameS = 'fotoknud.jpg';
header( 'Content-type: image/jpeg' );
readfile( $filenameS );
?>
--- cut here: end ----------------------------------------------------
---
---
Tested successfully on Microsoft Windows XP Professional,
running PHP and Apache.
---
---
Book: see also:
---
[book: author = David Sklar, David / Trachtenberg, Adam - title = PHP
Cookbook - publisher = O'Reilly - 'Recipe 15.9. Serving Images
Securely']
---
[book: author = Lerdorf, Rasmus - title = PHP Programming - publisher
= O'Reilly]
---
---
Internet: see also:
---
----------------------------------------------------------------------