469,138 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,138 developers. It's quick & easy.

image gallery

Hi,

my goal is to create a website with an image gallery. i have about 6 buttons at the bottom of the page whcih when clicked will take you to a different album of photos.

i have created the login page and the next step is to create the upload form to a database.

these are the tables i am going to intened to use:

TABLE: Gallery
gID - auto incrementing unique ID
gDescription - Description

TABLE: Images
iID - auto incrementing unique ID
iImage - BLOB field to hold the image
iUploaderID - ID from USERS table
iUploadDate - Date of upload
iComments - image comments submitted with the image
iGalleryID - ID from GALLERY table

but i have no idea how to upload the image to the database. i know you should upload an actual file but just a path to a folder. could anyone assist me on how to do this please.

Thanks
Jan 10 '10 #1
4 1782
Atli
5,058 Expert 4TB
Hey.

Check out this article.
It explains how to do exactly what you are trying to do.
Jan 11 '10 #2
thanks for your reply. i have got it all to work so the file uploads to the folder images which is what i wanted. but isnt this way storing the file on the database. isnt it better to point the directory to the path of the file as it is faster? or is your way fast?

another question is if i stick with your way of uploading the file how would i display the images. do you have a tutorial?

thanks
Jan 11 '10 #3
Atli
5,058 Expert 4TB
Yes, it is generally best to store the images on the file-system and save just the path to the image in the database. Storing the image itself inside the database - like my article demonstrates - tends to create extra overhead, which in turn decreases performance.

If you don't have any reason to put the image into the database, you really should avoid it.

another question is if i stick with your way of uploading the file how would i display the images. do you have a tutorial?
That depends on what you mean. If you are just talking about downloading individual images, then phases #3 and #4 of the article do just that.
However, If you want to display the image as a part of a HTML page, all you would have to do is create a <img> tag and set the src attribute to the "get_file.php" script.

Basically, in line #37 in phase #3 of the article, you would just have to change:
Expand|Select|Wrap|Line Numbers
  1. <td><a href='get_file.php?id={$row['id']}'>Download</a></td>
to:
Expand|Select|Wrap|Line Numbers
  1. <td><img src='get_file.php?id={$row['id']}' alt='{$row['name']}'></td>
The src attribute of the <img> tag expects to get sent a proper image content-type and valid image data. It doesn't care whether or not that is coming from an actual image or a PHP script that "imitates" an image.

The "get_file.php" script just sends back the content-type and data for the file ID you pass to it, so if that file is an image, the response from the script will "imitate" an image. A browser would see no difference between that and if the same image had been save on - and served from - the file-system.
Jan 12 '10 #4
when i try you phase 3 code it just prints out the files names and description like shown:

general shop.jpg 0 523861 2010-01-11 14:29:24 general shop.jpg

doesnt display a image. do i have to have phase 4 aswell to display it?

what i want to do is create a image gallery of the images that are stored on the database, preferablly i dont want to store any files on the database just a file path do you have a tutorial for that?

thanks for helping
Jan 12 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Perttu Pulkkinen | last post: by
8 posts views Thread by Chris Dewin | last post: by
4 posts views Thread by RE Kochanski | last post: by
1 post views Thread by gescom | last post: by
10 posts views Thread by cjparis | last post: by
25 posts views Thread by Gilles Ganault | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.