Jump to content

Store picture images in a database


Recommended Posts

Is there a way to store jpg files in a database field that can later be extracted into a dynamic variable for display on a web page. Everything I've tried doesn't work. I can't get the picture to display only the name. I can get the picture to display using html code img src and the path to the image but I want to be able to replace the file name in the path with a variable that holds the name of the image. Tried using PHP code but when I try that, it displays the name of the file name for the picture but not the picture or doesn't display anything at all.

<td><p align="center"><img src="../images/summer/PC051103.JPG" width="200" height="300" /></p>
<?PHP
$picture="../images/blue spruce/PC051116.JPG";
echo "$picture";
?>
Any suggestions? Maybe it can't be done.

 

Link to post
Share on other sites

A variable should work. Try this:

<?php$picture = '../images/summer/PC051103.JPG';?><img src="<?php echo $picture; ?>" width="200" height="300" />

I would recommend updating your knowledge of HTML. Learn HTML 5 and CSS. Your current HTML is really outdated.

 

It would be good to go through the PHP tutorial as well. "<?php" should be lowercase and when printing a variable you shouldn't wrap it in quotation marks.

Link to post
Share on other sites
  • 2 weeks later...

Storing images in a database is not recommended. This can cause more server load on the database's server. But you can store the paths of the the images in respect of their users or uniqueness in the database.

Link to post
Share on other sites

I've stored the path in the database but when I try to retieve it to a variable, such as $picture, it will not display using the variable. I can echo the variable by itself to see what is contained in the variable and it is the path along with the image name.

 

Here's a short page I made to test the image display capability:

<?phpsession_start();require('adminconnect.php');$extract = mysql_query("SELECT * FROM Catelog")or die(mysql_error());$row_saleitems = mysql_fetch_array($extract);$numrows = mysql_num_rows($extract);$_SESSION['itemtoedit']=$ItemToEdit; $Pix = $row_saleitems['pix'];echo "Number of rows: $numrows";echo"Picture path: $Pix";?><!DOCTYPE <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><style type="text/css"><!--#apDiv1 { position:absolute; left:425px; top:221px; width:200px; height:341px; z-index:1;}--></style><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>STMRR - Summer Trees</title> <link href="style.css" rel="stylesheet" type="text/css" /><style type="text/css"><!--body { background-color: #006600;}--></style></head><title>Test Image Display</title></head><?php$picture = '../images/winter/PC051089.JPG';echo "$Pix";?><body><div id="apDiv1"><img src="<?php echo $picture; ?>" width="200" height="300" /></div></body></html>

 

To run this script the url is stmrr.com/protectedpages/testimage.php

Link to post
Share on other sites

Invalid html layout, can't tell what real problem could be, unless the site properly validates.

 

css style tags outside of <head> </head>, 2 x title tags, php echo not within <body></body> tags.

 

In other words, please validate before posting.

Link to post
Share on other sites
  • 2 weeks later...

Storing images in a database is not recommended. This can cause more server load on the database's server. But you can store the paths of the the images in respect of their users or uniqueness in the database.

Lol i was angry read your comment here but the las i read only need name of file !

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...