user1434156
user1434156

Reputation:

URL Imageupload / Database set up

I am trying to store an image in my database via the URL(image location). I will like to only store the file name and the php will complete the url. My question: Do i need to add an id field to my table? Also the file maybe different ext(jpg, gif, png) how can the php determine that?

If your curious, I am using this image upload from this SITE

The URL that is generated by the code:

http://www.example.com/imageupload/uploads/medium/uniqueimagename.jpg

My database structure:

size: medium
name: uniqueimagename
ext: jpg/png/gif

Upvotes: 0

Views: 127

Answers (4)

Sardonic
Sardonic

Reputation: 126

Why would you need an ID field? As long as the 'uniqueimagename' column contains unique values that's your identifier.

You also don't need to have a separate column for the image type. The image name will contain the extension.

Upvotes: 0

Rakesh Shetty
Rakesh Shetty

Reputation: 4578

you can pass the image name like this www.example.com/imageupload/uploads/medium?img=uniqueimagename.jpg and you can get name by using $_GET['img'] and yes you have to store the id into your database.Also dont worry abt the extension because the img will store in your folder and just fetch the image name from your db and display in your img tag

Upvotes: 1

jcho360
jcho360

Reputation: 3759

I think you don't need to.

When you store the Image Name, I.E:

uniqueimagename.jpg

you'll store the extension too, and usually all the images go to the same folder so the path is common.

In PHP you have $_FILES["file"]["type"] variable to know the extension of the file. (or you can use explode like here)

if you want you can save the extension apart from the picture's name, but that's up to you

Upvotes: 0

KenL
KenL

Reputation: 875

The database field that is will hold the image should be a binary. The image name should or could hold the full name; that is with the file extention. Your code can strip the .gif from the the fullname prior to displaying the name.

The other way you can do this is just hold the naming info in the database and the actual image in a folder on your web site.

Upvotes: 0

Related Questions