note 38838 added to features.file-upload

From: Date: Thu, 08 Jan 2004 10:32:34 +0000
Subject: note 38838 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-63144@lists.php.net to get a copy of this message
If you have put an image into Mysql and want to get it to put onto a web page, here's a code for it so that you don't have to experiment. We have a database called "test" containing a table called "images" with columns "id", "mime", "data". Let's call this a "getimg.php": <?php $conn=mysql_connect(); mysql_query("use test"); $res=mysql_query("select * from images where id={$_GET['id']}"); $row= mysql_fetch_assoc($res); mysql_close($conn); header ("Content-length: ".strlen($row['data'])); header ("Content-type: {$row['mime']}"); echo $row['data']; ?> You can now display an image from the database by: <img src="getimg.php?id=1"> ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38838 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38838&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38838&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63144) next »