[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Image Display from non web root folder

Asked by highlawn in Web Images, Hypertext Markup Language (HTML), PHP Scripting Language

Tags: HTML PHP

I have been reading up on file upload security and the guidance (see here: http://www.scanit.be/uploads/php-file-upload.pdf but also it appears elsewhere) is to do the following:
1. Keep uploaded files in a folder NOT accessible by the browser - i.e. out of your webroot.
2. Change the file names so that they are not the same as the uploaded file and not easily guessed

In my script I check that it is an image file (as that is what I am uploading) and I check sizes and the like but that is not enough. I do number 2 above as I have to keep them in a database attached to the members' profiles.

However, I am having some difficulty sorting out how exactly to do number 1.

When the image is uploaded it is stored in the file area, but when I want to display it, I don't just want to send the raw image. I want it to be resized to thumbnail and to also be part of a lightbox object so that when clicked it is accessible. It is all currently working with the directory within the webroot, but I can't get it to work if the directory is outside the webroot.

Presumably, this is because the browser cannot find the location (not in webroot) and so I can't use html to tell the browser how to treat it. So, I could use PHP to send the stream (imagejpeg for eg) to the browser, but I also want to be able to pass the resize parameters and the lightbox links.

Now, I could always hold copies of the images as thumbnails and remove the first issue, but I can't see quite how I can wrap the html around an image stream from PHP.

I thought about using a temporary file in the webroot - so picking it up from outside, creating a temp in a webroot folder and then using that for the html. It seems a lot of messing around.

So, first question is - is this necessary? Is the security chap correct here? Should the files be stored outside the webroot for security?

If so, then how best may I achieve the equivalent of the following code which uses a file in the webroot.

Many Thanks - and I hope I've explained that clearly!

For info my web root is under /srv/public/html/domain.com - which maps to domain.com in the browser. I currently have the files under domain.com/images - I was intending to put them under /var/www/images - /var not being accessible by the browser.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
while ($img = mysql_fetch_array($gallery))                      // Get the images
        {
            $cap=stripslashes($img['caption']);                               // Image caption for lightbox
            $ttl=str_replace("'","",$img['title']);                                 // Gallery title to group images
            $imp="images/".$img['path'];                                         // image for html
            $is = img_resize("images/".$img['path'],90);                // make thumbnail
            $img ="<img src ='images/".$img['path']."'".$is.">";      // construct html for output
            $lightbox=" rel='lightbox[gal]' title='".$cap."'";              // lightbox parameters
            echo "<td width='25%'>";
            echo "<a href=\"$imp\" rel=\"lightbox[$ttl]\" title=\"$cap\">".$img."</a></td>";  // o/p to brw
            $nl++;                                                                         // four images per line
            if ($nl == 4) { echo "</tr><tr>"; }
        }
[+][-]08/15/09 03:22 AM, ID: 25104759Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/15/09 03:27 AM, ID: 25104769Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/15/09 04:24 AM, ID: 25104952Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/15/09 05:13 AM, ID: 25105108Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/15/09 05:26 AM, ID: 25105152Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Web Images, Hypertext Markup Language (HTML), PHP Scripting Language
Tags: HTML PHP
Sign Up Now!
Solution Provided By: spule
Participating Experts: 2
Solution Grade: B
 
[+][-]08/15/09 11:45 AM, ID: 25106429Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/15/09 11:15 PM, ID: 25107959Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/16/09 08:46 AM, ID: 25109315Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/16/09 09:12 AM, ID: 25109392Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625