Jump to content

[SOLVED] Include images outside of webroot


peranha

Recommended Posts

I was woundering how I can include images from outside the webroot.

 

Here is my webroot

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\site1

 

Here is where the images are

C:\site1\pics

 

In my database I put in

C:\site1\pics\75f623134468b269841a53da460221b17daca231.jpg

 

I am not sure if this needs to be here, or if there is a configuration that needs to be changed in the config file.

Link to comment
Share on other sites

I would suggest using the db id of your images combined with a php script to retrieve your images outside the web root. Then your image tags would look something like this:

<img src="getimage.php?id=24" />

 

The script for getimage.php could look something like this (left out validations that should occur):

<?php

$id = $_GET['id'];
$result = mysql_query("SELECT path FOM images WHERE id = $id");

$image = mysql_fetch_assoc($result);
$path = $image['path'];

$extension = substr($path, -3); 
if($extension == "jpg"){ 
    header("Content-type: image/jpeg"); 
}elseif($extension == "gif"){ 
    header("Content-type: image/gif"); 
}
readfile($path); 

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.