HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Display a picture (.jpg or .gif) from a mysql table
Goto page 1, 2  Next
Post new topic   Reply to topic    HTML Help Forum Index -> PHP
View previous topic :: View next topic  
Author Message
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Sun Feb 25, 2007 11:45 am     Display a picture (.jpg or .gif) from a mysql table Reply with quote

I am new to web programming.

I've been programing in VB for a while. Nothing commercial mostly easy stuff for work and myself.

I volunteered to help my daughter add a function to her website. So here is my problem.

I have code to add pictures to a MYSQL database. Now I can't seem to figure out how to get them back out so we can see them.

The MySQL doesn't seem to be a problem (yet), also I'm trying to learn PHP.

Any pointers or code samples will be greatly appreciated...
coberr



Joined: 28 Feb 2007
Posts: 29

PostPosted: Wed Feb 28, 2007 12:04 pm     Reply with quote

Do you want to load the 'full' image in your database?

What I usually do is to load the images in a folder "images" and then the name of the pic (i.e. "myphoto.jpg") in the database, so i retrieve the name of the pic with:

Code:
<?php
$connex = @MySQL_pconnect(server,login,password);
$sql_query = "select picname from photos where...";
$result = @MySQL_query($sql_query,$connex);
$row = @MySQL_fetch_array($result);
?>


and then:

Code:
<img src="'<?php echo $row['picname'];?>'" alt="photo">


or you can also embbed your HTML code in PHP this way:
Code:
echo "<img src=".$row['picname']." alt='photo'>";


I'll try to find how to load the pic in the database and post it here if nobody else does it before Wink

Regards,
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Wed Feb 28, 2007 12:33 pm     Reply with quote

From what I can see all that is doing is putting the name of the picture in the img src. I'm trying to display the actual image. Thanks though..
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Wed Mar 07, 2007 6:31 am     Reply with quote

I can't seem to get that example to work. How would I prepend a directory name to the picture name?
coberr



Joined: 28 Feb 2007
Posts: 29

PostPosted: Wed Mar 07, 2007 11:52 am     Reply with quote

You load the photo in a folder at your server. Let's call it images. Then you retrieve $row['picname'].

Finally you can do:
Code:
<?php
.....
$path = "./images/".$row['picname'];

/* It will be "./images" or "../images" depending on the depth of the php file.
You can also use $_SERVER[DOCUMENT_ROOT]."/images/".$row['picname'];
Search more about $_SERVER[Doc_root], because i'm doubting slightly about how it really is.*/


Regards,
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Thu Mar 08, 2007 6:10 am     Reply with quote

Thanks for the help.

I'm still not having any luck but I think I'm close now.

A little more explaination maybe helpful.

The images are in a folder (picture_library) directly under where the php file is. The php file is in httpdocs.

I'm trying to put the information into a 2 Column table.

When I view the page I see the correct information in the 1st column but in the 2nd column all I see is an icon (I think it's the one you get when the browser can't find an image) and the word photo.

Here is the source:
// Display the Name & Picture in a paragraph
while ( $row = mysql_fetch_array($result) ) {
?>
<tr>
<td><a href="#" onClick="MM_openBrWindow('<?=$row['url']?>','url','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes')">
<?=$row['description']?> <br> <?=$row[filename]?>
</a>
<td>
<?PHP $path = "$_SERVER[DOCUMENT_ROOT]/picture_library/".$row['filename']; ?>
<img src="'<?php echo $path;?>'" alt="photo">

</td>
<?php
}

?>
</font></td>
</tr>


******************************************************


Here is what I see when I view the source of the page:
<td><a href="#" onClick="MM_openBrWindow('','url','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes')">
First Image <br> Finale-1.jpg </a>
<td>
<img src="'/home/httpd/vhosts/lupusonline.org/httpdocs/picture_library/Finale-1.jpg'" alt="photo">

</td>
<tr>

I really feel I'm close but don't understand HTML enough to correct my problem.

Thanks again for all the help.
coberr



Joined: 28 Feb 2007
Posts: 29

PostPosted: Thu Mar 08, 2007 7:09 am     Reply with quote

garykoz wrote:

<img src="'<?php echo $path;?>'" alt="photo">


Try:
Code:
   <img src="<?php echo $path;?>" alt="photo">


or:
Code:
   <img src='<?php echo $path;?>' alt="photo">


Why do you use "' ? Just one of them, not both; because then you are sending to the website the string where the photo is.

I hope it will work out now.

Regards,
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Thu Mar 08, 2007 10:22 am     Reply with quote

That did it.....

Again THANK YOU for all... your help.
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Fri Mar 09, 2007 8:07 am     Reply with quote

When I showed this to my daughter she still has a problem (typical user...). She needs to be able to stop people from copying the pictures from her Web site.

That is why I thought storing them in the database and then just displaying them on the fly would be the way to go. That was my original problem, I guess I didn't explain it properly.

I don't know if this is the proper Forum. How do I find a place on the server where the picture files can be stored but not be copied from?

or

Is my original thought of retreiveing them the database and displaying the the way to go. If so how would I go about that?
coberr



Joined: 28 Feb 2007
Posts: 29

PostPosted: Sun Mar 11, 2007 1:40 pm     Reply with quote

With this all that you're doing is loading the pics on the web, so everybody who can use the right button of the mouse will copy the photos.

Just disable it. I'll try to find out how. I think it can be done using javascript.

Regards,
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Sun Mar 11, 2007 4:00 pm     Reply with quote

There is a way to disable it in the FAQ.
But if you read the rest there are ways of getting around it.
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Tue Mar 13, 2007 5:34 am     Reply with quote

I mentioned disabling the button to my daughter and she knows how to do it.

What I'm tring to do is hide where the the pictures are located on the server so when you view the source you can't see where they are located. That's why i thought maybe storing them in a database whould do that. My other thought was putting them into a hidden/secure directory. Another thought I had was to put information into a php include somehow.



Here is the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Lupus Online :: Resources for the Internet</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="main.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body>
<div id="title"><img src="images/logo.gif"></div>
</div>
<div id="nav" class="links" align="center"> <a hrefGaryMaster2.php?cid=1">organizations</a>
:: <a href="GaryMaster2.php?cid=2">information</a> :: <a href="GaryMaster2.php?cid=3">research</a>
:: <a href="GaryMaster2.php?cid=4">networking</a>
:: <a href="GaryEvents.php?cid=5">EVENTS</a>
:: <a href="comments.htm">comments</a>
</div>
<div id="content">
<p align="left">
<h3 align="left">
<h5 align="left"><font face="Tahoma, verdana, arial, helvetica, sans-serif"><br><br>Here
are the Pictures.
<br>

<?php
include ('/home/httpd/vhosts/lupusonline.org/httpdocs/includes/connect.txt');
?>

<p>&nbsp; </p>
<table width="80%" border="1" align="center" cellpadding="2" cellspacing="2" bordercolor="#660066" id="all results">
<tr>
<td> <font size="-1" face="Tahoma, verdana, arial, helvetica, sans-serif">&nbsp;
NAME </font></td>
<td><font size="-1" face="Tahoma, verdana, arial, helvetica, sans-serif">
PICTURE </font>
<?php

// Request the Name & Picture
$result = @mysql_query("SELECT * from filestore WHERE left(filename,6) = 'finale'");
if (!$result) {
die('<p>Error performing query: ' . mysql_error() . '</p>');
}

// Display the Name & Picture in a paragraph
while ( $row = mysql_fetch_array($result) ) {
?>
<tr>
<td><a href="#" onClick="MM_openBrWindow('<?=$row['url']?>','url','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes')">
<?=$row['description']?> <br> <?=$row[filename]?>
</a>
<td>
<?PHP $path = "picture_library/".$row['filename']; ?>

<img src="<?php echo $path;?>" alt="photo">
</td>
<?php
}

?>
</font></td>
</tr>

</table>
<p align="center">&nbsp;</p>
</div>
</div>


</body>
</html>


I'm in over my head so any help will be grwatly appreciated.
coberr



Joined: 28 Feb 2007
Posts: 29

PostPosted: Tue Mar 13, 2007 8:04 am     Reply with quote

My dear garykoz,

No matter if you try to hide the folder or if you try to load the images to a database. Those are only solutions to storage the photos. When you make them appear on the web you're loading them on the web page and from it is where i can take them. As i haven't got any access to your database or to the folder i cannot get them straight from there. But as i tell you, they've been loaded on your web.

At least, this is the way i think it works.
garykoz



Joined: 25 Feb 2007
Posts: 13
Location: Rochester Hills, MI

PostPosted: Tue Mar 13, 2007 12:09 pm     Reply with quote

So if I use files on the server I need to restrict access to the site somehow?

I'm still trying to figure out how to display them straight from the database. I have them loaded into the database as a MEDIUMBLOB file type. I've found a PHP function called "imagecreatefromstring". The format is imagecreatefromstring(image). The description says "Creates an image from the image stream in a string.

Now I'm searching for examples of the function.
coberr



Joined: 28 Feb 2007
Posts: 29

PostPosted: Thu Mar 15, 2007 8:51 am     Reply with quote

garykoz wrote:
So if I use files on the server I need to restrict access to the site somehow?


Yes, I'm afraid so.

I know there's a way of doing what you're trying. The advantage of it, if i'm not wrong, is that you can get different sizes for the same pic with only one pic with PHP. On the other hand is that it's not very easy, so many people prefers to have two sizes of the same pic and show the small one first and the bigger one when you ask for an enlargement of it.

If i find out, i'll post it here. Wink

Regards,
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> PHP All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial