Page 1 of 1

display a graphic stored as a blob in mysql, along with text

Posted: Fri Feb 19, 2010 10:55 am
by hugeness
Hi

have built a form where users upload a graphic as a blob (yep, i really want them to do it this way!) but having an issue displaying both the graphic and the text they entered on a 'review page'.. basically, i can get either the graphic or the text to show, but not both.. i believe this is something to do with the headers, and that i can solve the problem using an include file, does anyone have a good example of how to do this? i have not yet found an explanation that i understand fully..

here is a summary of my review page..

Code: Select all

 
<?php 
 
$_SESSION['othf']= $_POST['othf'];
$_SESSION['newRight']= $_POST['newRight']; 
$_SESSION['un']= $_POST['un'];............................
 
passing the variables from the previous page.. all works ok
 
..............$off_yn = $_POST['off_yn'];
$off_more = $_POST['off_more'];
$ts5 = $_POST['ts5'];
 
 
//upload file/logo
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
 
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
 
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
 
$conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); 
$db = mysql_select_db('minisite',$conn) or trigger_error("SQL", E_USER_ERROR); 
 
 
$query = "INSERT INTO upload (name, size, type, content,pw,un ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content','$pw','$un')";
 
mysql_query($query) or die('Error, query failed');
//include '../library/closedb.php';
 
}
 
$row = mysql_fetch_array(mysql_query("SELECT content FROM upload WHERE id = LAST_INSERT_ID() ")); 
header("Content-type: image/jpg"); 
print $row['content'];  
 
 
<!-- NOTHING SHOWS BELOW THIS POINT -->
 
$tc4 = $tc1.'<br/> '.$tc2.'<br/> '.' '.$tc3;
?> 
have tried this next part echoed out as a php string, no success..
 
<html><head><title>Upload Logo</title>
<style type="text/css">
 
a {
    color: #e16500;
}
STYLE SHEET BITS HERE
 
</style></head>
 
<body><div id="main"><p>The following information was successfully added to our database ... please take a few moments to review and update as necessary:</p>
<h3>Registration information created: $cre </h3>
<p>File $fileName uploaded</p>
<p>Your Username is $un and your password is $pw.</p>
 
<p>You are: $fn $ln, $ttl</p>
LOTS OF MIXED HTML AND VARIABLES 
 
...... ype="hidden" name="ts7" value=" $ts7">
<input type="hidden" name="ts5" value=" $ts5">
<input type="submit" input id="update" value="Click here to update your details" >
</form>   </body>
</html>
 

so, the graphic uploads, and displays, but just now, the text doesnt show. i've tried writing the text html as a php string, but no success.. there must be a way of including a graphic stored as a blob with other text.. ? i have looked for hours, but maybe i'm just not searching smart?

also.. have seen an example which again i don't quite understand, but could work for me.. instead uploading the graphic converted to base64.. does anyone know if this method works around the conflict displaying a blob and text appears to have?
heres an example of converting to base64.. http://www.tutcity.com/view/image-databasing.9514.html
thank you.

Re: display a graphic stored as a blob in mysql, along with text

Posted: Fri Feb 19, 2010 11:10 am
by AbraCadaver
You need to display the page as an HTML page without the image header and then use an <img> tag with the src set to a PHP file that grabs the image from the db and outputs the header and image. See here: viewtopic.php?f=1&t=110171&p=582727#p582727