• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

store image into db

Guest
May 20, 2007 May 20, 2007

Copy link to clipboard

Copied

I am using sql server db. I would like to store image into db. How can i store image into db and read it after that.

thanks
TOPICS
Advanced techniques

Views

370

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 21, 2007 May 21, 2007

Copy link to clipboard

Copied

Unless there is a compelling reason for storing the image in the database, I'd suggest you store the image in an image directory and store the filename of the image in the database. For example, if you store myImage.jpg into a directory named imageDir, you can store the filename "myImage.jpg" in the database. To display the image, retrieve it as the variable showImage and display it using <IMG SRC="imageDir\#showImage#" ... >

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 21, 2007 May 21, 2007

Copy link to clipboard

Copied

Thanks, You guys have any sample code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 21, 2007 May 21, 2007

Copy link to clipboard

Copied

There is some debate as to what the recommended approach would be.

I am of the opinion that storing the image itself in the database, while technically possible, is not the best solution for most of the scenarios I have come across.

As has been suggested, I also recommend storing the image itself in a priviledged directory on your server, and then storing the filename to that image in your database.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 21, 2007 May 21, 2007

Copy link to clipboard

Copied

It depends on what you want to do.

Are you allowing end users to upload images, and then referencing those images on a page, or are you, as the developer, maintaining the images and displaying them?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 21, 2007 May 21, 2007

Copy link to clipboard

Copied

I did figure it out. Only help i need how can i store multile image into db.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 21, 2007 May 21, 2007

Copy link to clipboard

Copied

LATEST
That depends on how your database is structured. If you anticipate mutlipe images per record in your DB, it might make sense to create a separate table with a one-to-many relationship between the main table and your images table. That would allow you the flexibility to store as many images as you want that relate to a single record in your main table.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation