Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 10:04 AM   PM User | #1
XmisterIS
Regular Coder

 
Join Date: Jun 2010
Posts: 239
Thanks: 50
Thanked 6 Times in 6 Posts
XmisterIS is an unknown quantity at this point
Best way of serving images?

I have a website which serves images in various sizes (e.g. wikipedia allows you to view the same image in different sizes). The images are uploaded by the users of the site.

Currently, I use PHP to process the uploaded images and store them in various sizes in a database (e.g. small/medium/large).

What is the best way to serve the images? I can think of:

1) retrieve each image from the database each time it is required. (*** This is the way I currently do it ***)

2) store the images as files in a folder in the public web directory and simply link to them.

3) Using the database-retrieval method, keep a store of previously-requested images in $_SESSION and serve them from $_SESSION each time they are required.

Option 2 is probably the most efficient, but I don't like the idea of having a writeable folder in the public web directory. Also, I suspect that doing this would leave the folder open to site-scrapers who could simply retrieve every image stored there.
XmisterIS is offline   Reply With Quote
Old 01-09-2013, 07:00 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
I would serve the smallest and link the larger (ie view larger) and then fetch it if they click it
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 01-10-2013, 05:39 PM   PM User | #3
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
You can take advantage of .htaccess to block any 'site-scrapers'.

Option 2 is the best option, with use of .htaccess.

Remember that SEO requires that images that are displayed as X width and Y height should be (in its' original dimensions) X width and Y height. Never use code to resize an image.
TFlan is offline   Reply With Quote
Old 01-21-2013, 09:45 PM   PM User | #4
alliv105
New Coder

 
Join Date: Jan 2013
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
alliv105 is an unknown quantity at this point
Serve your images from the Amazon Cloud and store the common denominator path in the DB. For instance, let's say you have 3 sizes of images. Create three "buckets" in amazon cloud front for each size. Within each bucket, create identical paths to the pictures. Hence, you will have something like: SmallBucket/images/image1.jpg, MediumBucket/images/image1.jpg, BigBucket/images/image1.jpg. All images and paths are the same except for the bucket name.

In your code, you will know when you need a large picture versus a small picture. All you'll need to change is the bucket name within your URL.
alliv105 is offline   Reply With Quote
Old 02-20-2013, 09:16 AM   PM User | #5
Biztech
New to the CF scene

 
Join Date: Feb 2013
Location: India
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Biztech is an unknown quantity at this point
You have shared really very helpful information which is helped me so much and I think it will help to many other people who do not know about it.
Biztech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:16 AM.


Advertisement
Log in to turn off these ads.