Solved

Best way to store images in a blog/cms system

Posted on 2011-03-06
8
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
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.

636 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