Jump to content

Should the uploaded image file path be stored in the same table as the record or seperatly, in mysql database?


Recommended Posts

I am curious to know what the best practice is for something like this.

 

I as a user post a record.  In that record is an option for me to upload images.  Since I am storing my record in "records" table, is it a good idea to ALSO store the record images(file paths) in the same table? Or would it make more sense to store the images is a separate table called "images"? 

If a user can have multiple images uploaded, then the relationship is 1 record -> to many images.

 

This requires that you have a separate images table with the foreign key of record_id to link the image back to its user.

If a user can have multiple images uploaded, then the relationship is 1 record -> to many images.

 

This requires that you have a separate images table with the foreign key of record_id to link the image back to its user.

 

Yes the record will have multiple images.  So I guess it's best to separate them.

 

Thanks.

In addition to Gizmola's advice I suggest that you do NOT store the actual image files (.jpg,.png,.gif, etc.) in a table. No need for that. Store the location/name of the image file in your record and save the image file in that place. If the images are going to be displayed on your html pages, then store them in the web-accessible tree.

 

As for your paths - if you have control over the images and directory structure I would keep the path to the folder(s) as a constant for your appl and just use a relative path in the record. Then when things get moved around for some reason you simply create a new tree and copy the old one under it and then modify the appl constant to point to the new location. All the relative paths in the records will still work just fine.

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.