Jump to content
Larry Ullman's Book Forums

Display Multiple Images - Msg Board Thumbs


Recommended Posts

Hi

 

I transferred my site to a hosted Server recently and  the issue of displaying images - user avatars associated with forum posts ( avatars  are located in an  images folder outside of the root directory ) - reared it's head.

 

Previously, on my local host, I accessed the users avatars using code similar to the following:

 

$thumb = '<img src="../uploads/avatar.jpg">';

 

Following much heartache, I now realise ( as highlighted in CH.11 ) that a user's browser cannot access a file which is outside of the root folder.  As Larry points out, a proxy file is required.

 

My questions are -

 

 

A. On first reading, it seems I will need to invoke the header() function to find each image. However, this function would be required quite a way into my particular show_forum_posts.php script.  Larry says the header() function MUST NOT be preceeded by any other characters...... ?????

 

I don't know how to resolve this.

 

 

 

B. Each forum post in a particular thread, and the associated avatar for the poster,  is sourced using a SQL query and a while loop.

 

 

 

What is the most efficient way ( in plain language  ) to structure the solution?  Is it better to collect all the avatar details for a particular forum page in one go, so that the user's browser can somehow make one visit to the images folder and find the required avatars, or is the browser destined to make multiple visits to the folder, one visit per avatar image?  Without knowing why, it would seem to be a much slower process if this were the case, and potentially damage site performance.

 

 

 

Hope all of the above makes sense. Many thanks for any advice and tips.

Link to comment
Share on other sites

Note that the proxy script you write to retrieve the images will run on a separate process thread, thus the header issue is not a problem.

 

For example, all the images you want to load via the proxy script will require markup like the following:

<img src="image_proxy_script.php?img=image1.png">

You can have as many of those image tags as you want on the page, as they will all invoke separate processes, thus not causing any issues.

 

To answer your second question, I imagine that you'd want to construct a data model that allows you to loop through an array where each element is a post and all the data surrounding that post, including the URL to the avatar image.

As such, one SQL call to get all the avatar images makes the most sense to me. In fact, I imagine that with the proper joins, you could get all the post info you need in one query.

 

With all that said though, please note that for each img tag you have in your markup, a separate HTTP request will be made for those images. That is how the protocol works and is unavoidable.

Link to comment
Share on other sites

Thank you so much for your reply HartleySan. Things becoming clearer now.

 

In hindsight, I may have misled unintentionally with the wording of the second question. However in saying that each image tag requires a separate HTTP request, you have answered the question I meant to ask!

 

I think I know how to proceed now.

 

As an observation, msg board pages with very many posts must create a huge amount of traffic between browser and image folders? And as for photo galleries.....?!!

 

Thank you again.

Link to comment
Share on other sites

 Share

×
×
  • Create New...