image retrieving from mysql problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
strazdinjsh
Forum Newbie
Posts: 1
Joined: Mon Nov 15, 2010 3:40 am

image retrieving from mysql problem

Post by strazdinjsh »

That must be very simple but i can not step over the issue what i have got.
1. i have file which displays the image called index.php with source code of
--------------------------------------------------------------------
...
<img src="sample.php?id=42" />
...
--------------------------------------------------------------------
2. then i have file sample.php with source code
-------------------------------------------------------------------------------------
require("sys/functions.php");
dbConnect();
$id = $_GET["id"];
if(!isset($id))
{
echo "select an ID";
}
else
{
$res = mysql_query("SELECT * FROM gallery where id=$id");
$row = mysql_fetch_assoc($res);

header("Content-type: image/$row[extension]");
echo $row['image'];
}

-------------------------------------------------------------------------------------------
3. i have successfully uploaded file to MySQL, i can see it as a record with id=42 (image - that is the actual file, extensions - image extension)
4. when launching the index.php i am not getting an image but still can get a file size, approx. must be right 248kb. image itself does not display

Could anyone have a look and give me some idea to start with... thanks a lot.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: image retrieving from mysql problem

Post by AbraCadaver »

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply