0

I am trying to learn how to use Images stored in the server using a Database


In server my image is in the location /images/image.jpg


I have created a database called test456

I have a table named MyTable in the database test456

CREATE TABLE MyTable
(
_id INT(10) AUTO_INCREMENT,
Image VARCHAR(50)
);

I read a post that involved

Store the image location in the filesystem, than store it directly in the DB.

  • What is meant by it?
  • How to achieve this?
  • Just store the name of the image (in your case it is image.jpg) to the db and thats it. You know where it is located so just retrieve it from db and display it wherever needed – Vasanthan.R.P Sep 18 '13 at 04:46
  • Also, varchar(50) may not be a good idea depending on how you intend to store the url. If just filename then you might be safe, but if you're doing a full path that might be limiting. Yeah, not a good idea to have huge paths, but you never know. Suppose you're storing user uploaded files and preserving filenames. A user MIGHT upload a file with a ridiculous name. Alternatively, you could rename the uploaded images with their id's and store the path to the renamed file. That could be safe with varchar(50). Storing images in the DB COULD mean storing the bytes of a file using a blob data type – Kai Qing Sep 18 '13 at 04:49
  • in the database you can just store the path of image you need to upload image to your perticular folder and after the save the path of that image in database to call the path any time in image source to show your image – Vikas Gautam Sep 18 '13 at 04:49

2 Answers2

0

upload the image in the directory(server location of the image) and store the image path in the database as VARCHAR

Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43
0

table:

CREATE TABLE MyTable
(
    _id INT(10) AUTO_INCREMENT,
    imagePath VARCHAR(50)
);

HTML/PHP

<img src="<?php echo $row['imagePath'] ?>" />
bzupnick
  • 2,646
  • 4
  • 25
  • 34