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.

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); 

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.