Solved

Best way to store images in a blog/cms system

Posted on 2011-03-06
8
385 Views
Last Modified: 2014-07-22
I am in the process of developing a blog system. Users will be able to upload multiple images to a particular blog entry.  I am going to store the images in the file system.

My question is where to store the uploaded images? I have found some answers like below.

1. create folder for every blog with ID and store the images related to that blog.
   
   Images for Blog ID 1000000001 would be stored in folder: 10/00/00/00/01/abc.jpg

2. create folders by year and month (from blog entry creation date).
 
   Images for 2011/Mar will be store in folder : /images/blog/2011/03/abc.jpg.

3. create folders by user id (the user who uploads the images).

    Images for User ID 1000000001 would be stored in folder: 10/00/00/00/01/abc.jpg

I need to know which one is the efficient method.

I am planning to use CKEditor with CKFinder to edit and upload images. When the user uploads the images using CKFinder the images will be uploaded in the filesystem and <img> tag will be placed in the textarea. In this scenario How to store the uploaded images path to the db? Because later If I want to delete the blog , I should be able to delete all the images related to that blog.

Hope I explain my problem clearly.
0
Comment
Question by:aindi
8 Comments
 
LVL 3

Accepted Solution

by:
wwwdeveloper2 earned 250 total points
ID: 35048408
Will each blog have it's own directory?  If so, if it was me I would store the images inside an images directory for each blog.

I would need to know more about your directory structure and programming language to help out more.  

Assuming that each blog had it's own directory and it's own image directory, I would just simply store the file name in the db table and output the <img src>  based on the location of the file calling image.

Example <?php echo "<img src=\""$_SERVER['PHP_SELF']. "/images/" .$file_name_from_db . "\"/>"; ?>

Doing this would make it a lot more easier if you had to change your file structure for some reason.  If you were keeping parts of the file path in the db, it would be a nightmare to try and update it.

Also if the blogs each had their own directory and you decided you didn't need that blog any longer, it should be fairly simple to delete that blog's directory and run some edits on the db to remove rows associate with that blog.

Just some initial thoughts I had.  If you have more questions or want to provide more details to help me answer you questions, just let me know.

Good luck.
0
 

Author Comment

by:aindi
ID: 35053368
Hi wwwdeveloper2!

Thanks for your comment.

I am using php 5 with mysql on linux.

Still I am not clear about which way I should use to store the images either by creating a directory for every blog id or by year and month or by user id or a common directory for all blogs. I need to know the pros and cons of these and the best one to use. After that I will raise other questions related to this.

Thanks

0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 35063604
Ok, well that is all I have for now.  I gave what I would do.  The point value of this question isn't worth posting pros and cons for every single situation on how this can be accomplished.  It would be like writing a book.

Good luck.  Hopefully somebody else will have time.

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 5

Expert Comment

by:onemadeye
ID: 35086311
I think you could refer to WORDPRESS for how they store images (num#2 from your post) and I think it's good to separate the uploaded images by year and month.

Regards...
0
 
LVL 24

Assisted Solution

by:Alan Henderson
Alan Henderson earned 250 total points
ID: 35237927
I've recently started saving all my web images in Dropbox. If you put them in your Dropbox Public folder (or a subfolder of /Public) you can just right click on the image in Dropbox and copy the link to the image for pasting into your post/page.

If you don't have Dropbox you're missing the best free tool in cyberspace:
http://www.experts-exchange.com/Software/Office_Productivity/A_4137-Dropbox-data-backup-and-synchronization.html
0
 
LVL 24

Expert Comment

by:lenamtl
ID: 35840582
You should use method 1 because this will be easier for you
if you want to delete all images of one particulaer blog when deleting the associate blog.

method 2 will be harder to find which image goes with wich blog

method 3 if a user have more than one blog and you want to delete only one blog with associate images this will be also hard to find out.


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Joomla Website Malfunction 9 93
cookies analysis tools 2 72
Cordova Camera plugin fails 2 97
Office 365 Pass Username an Password in URL 3 45
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now