Hi
I am trying to take an image that I have stored in a MySQL database and display it to screen. My PHP is as follows for:-
<?php
ob_start();
//include the database connection file
include ($_SERVER['DOCUMENT_ROOT'].'\project\website\connect\databaseconnect.php');
$query = "select title, first_name, last_name, house_number, street, town, county, postcode, contact_number, emailaddress, username, password, image_title, image_file, image_type, image_size, expertise, about from trainer";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$title = $row['title'];
$firstname= $row ['first_name'];
$lastname = $row ['last_name'];
$house_number = $row['house_number'];
$street = $row ['street'];
$town = $row ['town'];
$county = $row ['county'];
$postcode = $row ['postcode'];
$telephone = $row ['contact_number'];
$email = $row ['emailaddress'];
$username = $row ['username'];
$password = $row ['password'];
$image_title = $row['image_title'];
$image_file = $row['image_file'];
$image_type = $row['image_type'];
$image_size = $row['image_size'];
$expertise = $row['expertise'];
$about = $row['about'];
echo $title;
echo $firstname;
echo $lastname;
echo $house_number;
echo $street;
echo $town;
echo $county;
echo $postcode;
echo $telephone;
echo $email;
echo $username;
echo $password;
echo $expertise;
echo $about;
header("Content-type: $image_type");
echo $image_file;
}
?>
Any help would be wonderful. It should be working. All i get displayed to screen is a picture box with a red x in it nothing else.
get image from mysql database using php
Moderator: General Moderators
Re: get image from mysql database using php
Problem solved. The echo [text] was interfering with the display of the message. I took out all the echo statements leading up to the header() statement and now I have display of the image. I can work with this. Thanks for anybody thinking of helping.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: get image from mysql database using php
you can't output anything to the browser before the headers, that's why its a header. dont' worry though a lot of people miss that when they are new.
this whole deal is pretty unnecessary anyway though:http://us2.php.net/manual/en/function.header.php wrote: Remember that header() must be called before any actual output is sent
Code: Select all
$title = $row['title'];
$firstname= $row ['first_name'];
$lastname = $row ['last_name'];
$house_number = $row['house_number'];
$street = $row ['street'];
$town = $row ['town'];
$county = $row ['county'];
$postcode = $row ['postcode'];
$telephone = $row ['contact_number'];
$email = $row ['emailaddress'];
$username = $row ['username'];
$password = $row ['password'];
$image_title = $row['image_title'];
$image_file = $row['image_file'];
$image_type = $row['image_type'];
$image_size = $row['image_size'];
$expertise = $row['expertise'];
$about = $row['about'];
Re: get image from mysql database using php
why dont you just input the img path into the database and echo the path into <img src="path"/>?
Re: get image from mysql database using php
hi nga
After trying to use a database to store the actual image, I have instead placed the directory path into the database as loading an image from the database took too long.
After trying to use a database to store the actual image, I have instead placed the directory path into the database as loading an image from the database took too long.