image gallery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saunders1989
    New Member
    • Jan 2010
    • 3

    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
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Check out this article.
    It explains how to do exactly what you are trying to do.

    Comment

    • saunders1989
      New Member
      • Jan 2010
      • 3

      #3
      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

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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.p hp" script.

        Basically, in line #37 in phase #3 of the article, you would just have to change:
        [code=php]<td><a href='get_file. php?id={$row['id']}'>Download</a></td>[/code]
        to:
        [code=php]<td><img src='get_file.p hp?id={$row['id']}' alt='{$row['name']}'></td>[/code]

        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.p hp" 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.

        Comment

        • saunders1989
          New Member
          • Jan 2010
          • 3

          #5
          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

          Comment

          Working...