MySQL Forums
Forum List  »  PHP

retrieving a photo from mysql database
Posted by: charlei lanahan
Date: March 17, 2009 08:19AM

i can save it to data base using this
<title>Upload Party photo</title>
<h1>Upload Party photo</h1>
<p>This form allows a user to upload a photo. </p>
<form action=<?php print $PHP_SELF; ?> method="post" enctype="multipart/form-data">
Picture to load: <input type="file" name="imageFile" size="50" />
<br/>Name ID <input type="text" name="nameID" size="4"/>
<br/><input type="submit" value='Upload'>


// print_r($_REQUEST);
// print_r($_FILES);
// should check that this is a valid nameID
if (!isset($_REQUEST['nameID'])) die("");
$nameID = $_REQUEST['nameID'];

// details of the file stored on the server are in the $_FILES array

$filename = $_FILES['imageFile']['name'];
$tempfilename = $_FILES['imageFile']['tmp_name'];

// get rid of any newline characters in the file
$tempfile = file($tempfilename);

//base64 is one possible encoding of a binary file into printable characters - it takes more space
//and takes time to code and decode but it can be manipulated as a string
//an alternative would be to save as binary but I have difficulty making that work reliably :-(

$image64 = base64_encode($imageJPEG);

// connect to the MySQL server
$dblink =db_connect();

//replace is used here instead of insert to insert or replace
$query = "replace into photo(photoID,image) values($nameID,'$image64')";
if(!$dbresult = mysql_query($query,$dblink) ) {
print "Query failed :";
print(mysql_error() . "<br/>");

// close the database
print("<p>$filename added, size = ". strlen($image64)."</p>");
print("<img src='getphoto.php?photoID=$photoID' />");


but it wont now come up with the photo.. arbgh!! please help

Options: ReplyQuote

Written By
retrieving a photo from mysql database
March 17, 2009 08:19AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.