Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Best way to store images in a blog/cms system

Posted on 2011-03-06
8
Medium Priority
?
393 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 1000 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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 1000 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 26

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

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

715 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