Jump to content

How best to store an image?


melloorr

Recommended Posts

Well, I am storing some of images on my server, but I have to type in the name myself which gets a bit boring and I may overwrite an old image by accident, so, I was thinking of having mysql auto increment the image names. But will this be suitable for images, or should it be text.

Link to comment
Share on other sites

You should store the images as files and not in a database. However, you can still put in the image names into the database.

 

If you don't want to overwrite old images you can just use file_exists() to see if that image already exists. If it does, just append some random characters to the end of the file name before you save it.

Link to comment
Share on other sites

You should store the images as files and not in a database. However, you can still put in the image names into the database.

 

If you don't want to overwrite old images you can just use file_exists() to see if that image already exists. If it does, just append some random characters to the end of the file name before you save it.

 

They are not stored in a database as such. They are stored in a folder, but I have the image names stored in the database so they are easier to call

Link to comment
Share on other sites

I just wanted to know if storing the images as numbers (i.e. 1.jpg), would be okay or if it would be best taht I use text instead. If i store it as numbers, then i wouldn't have to specify a name

 

There is nothing wrong with storing an image using a number for the filename.  The only difficulty would be if you look in that directory you just see a bunch of numbered files and won't know what they associate with.  That is not really a big issue though.  You could always use a number + the original file name.  Ex: 138_myfile.jpg where 138 is an auto-inc number and myfile.jpg is the original name.

 

It doesn't really matter what you name the image so long as your maintaining a reference by storing the name in your DB along with whatever data is associated with that image.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.