Jump to content

displaying images from a DB


bryanptcs

Recommended Posts

ok, so I have a form that is submitted to the DB containing client info and a thumbnail.  I also have a program that calls the data from the DB and displays the info in a table.  The problem I am having is in displaying the thumbnail.  It just displays a lot of code that i guess makes up the image.  Anyways, below is my code.  Any help would be great.  Thanks.

 

the upload form

<?php 
  include ("db.inc");
  
  $connection = mysql_connect($host, $user, $password) or die ("Couldn't connect to the server");
  $db = mysql_select_db($database, $connection) or die("could not select the DB");
  $companyName = Trim(stripslashes($_POST['companyName']));
  $companyWeb = Trim(stripslashes($_POST['companyWeb']));
  
 $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);
}

  $sql = "INSERT INTO ClientList (companyName, companyWeb, name, size, type, content) VALUES ('$companyName', '$companyWeb', '$fileName', '$fileSize', '$fileType', '$content')";
  $result = mysql_query($sql) or die ("Could not execute query");

  if($result == "yes")
  {
  header("Location: viewclient.php");
  echo "Client Successfully Added";
  exit;
  }
  
?>

 

the view the data code

 

<?php
  include("db.inc");
  
  $connection = mysql_connect($host, $user, $password) or die ("Could not connect");
  $db = mysql_select_db($database, $connection) or die ("Could not connect to DB");
  if ($_POST['delete']){
  	$deleteID = $_POST['delete'];
	mysql_query("DELETE FROM ClientList WHERE companyName = '$deleteID'") or die (mysql_error());
	echo "Successfully Deleted Client<p>";
}
  $sql = "SELECT * FROM ClientList ORDER BY companyName";
  $result = mysql_query($sql) or die("Could not execute query");
  
  echo "<table cellpadding='0' border='1' cellspacing='0' width='500' align='center'>";
  echo "<tr><td><font size='-2'>Press Below Button to Delete</font></td><td>Company Name</td>";
  echo "<td>Company Web Site</td><td>Thumbnail</td></tr>";
  while ($row = mysql_fetch_array($result))
  	{
		extract($row);
		echo "<tr><td align='center'><form id='form1' name='form1' method='post' action='{$_SERVER['PHP_SELF']}'><input type='submit' name='delete' value='{$row['companyName']}' /></form><td>";
		echo $companyName."</td>";
		echo "<td><a href='http://".$companyWeb."' target='_blank'>".$companyWeb."</a></td>";
		echo $content;
		echo "</tr>";
	}
	echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/40771-displaying-images-from-a-db/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.