Solved

Best way to store images in a blog/cms system

Posted on 2011-03-06
8
389 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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 25

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

735 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