Solved

Best way to store images in a blog/cms system

Posted on 2011-03-06
8
384 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:onemadeye
Comment Utility
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 23

Assisted Solution

by:Alan Henderson
Alan Henderson earned 250 total points
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Simple Mosaic Web Library 8 60
Pick image, show data 4 33
Form submit issue 11 52
work allocation; web development; vba; access; 4 46
Since I am currently running into this issue right now as I type this, I though I would share my experiences with moving a ModX Revolution site from one server to another.  It is not an easy task, but can be accomplished rather easily. The first …
Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

11 Experts available now in Live!

Get 1:1 Help Now