Retrieving a Binary Image from MySQL and Displaying it
Posted: Tue Jun 16, 2009 3:53 pm
I've been trying to make this work for about 1 1/2 days now without complete success.
I'm trying to make a web site (written primarily in HTML, but lots of PHP involved) in which a user would log in, click an "Upload Image" link, upload an image that gets stored in binary inside a MySQL database, then that image is displayed when the user returns to their post-log-in page.
Here's what I have so far for storing the picture in the database.
As you can tell, the code gets data from the form (on the previous HTML page) and formats the data so that it can't hurt MySQL. Of course, there is an INSERT statement later on, and the whole system up to this point works. When read straight from the database using a management tool and compared to the original image, it is exactly the same thing.
My problem comes when I try to retrieve that image. I have no idea how to do it! Ideally, there would be a javascript slideshow of all the pictures they've uploaded, but that will get asked in a different forum or I'll just learn javascript.
So far, I've been able to download a file (whose name is "download.php") that, once renamed, displays the picture correctly by calling this:
download.php
Even me reading my own question confuses me. If anybody needs more specific details or clarification, just ask.
Much appreciation!
Raptor354
P.S.: I've tried several examples off the Internet, but to no avail
I'm trying to make a web site (written primarily in HTML, but lots of PHP involved) in which a user would log in, click an "Upload Image" link, upload an image that gets stored in binary inside a MySQL database, then that image is displayed when the user returns to their post-log-in page.
Here's what I have so far for storing the picture in the database.
Code: Select all
addslashes(fread(fopen($_FILES['uploadedfile']['tmp_name'], "r"), filesize($_FILES['uploadedfile']['tmp_name'])));My problem comes when I try to retrieve that image. I have no idea how to do it! Ideally, there would be a javascript slideshow of all the pictures they've uploaded, but that will get asked in a different forum or I'll just learn javascript.
So far, I've been able to download a file (whose name is "download.php") that, once renamed, displays the picture correctly by calling this:
Code: Select all
<a href='download.php?SubmissionId=$data->SubmissionId'>Download</a>Code: Select all
$subid = $_GET['SubmissionId'];
$sql = "SELECT SubmissionTitle,Picture FROM Submission WHERE SubmissionId='$subid'";
$result = mysql_query($sql);
$data = mysql_result($result, 0, "Picture");
header("Content-type:'image/jpg'");
echo $data;Much appreciation!
Raptor354
P.S.: I've tried several examples off the Internet, but to no avail