peranha Posted August 22, 2008 Share Posted August 22, 2008 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 https://forums.phpfreaks.com/topic/120931-solved-include-images-outside-of-webroot/ Share on other sites More sharing options...
Poddy Posted August 22, 2008 Share Posted August 22, 2008 Dont save the full path in mysql use relative paths as in your example use pics/name.jpg if you want an image from a dirctory 1 level up from your files use ../name.jpg Link to comment https://forums.phpfreaks.com/topic/120931-solved-include-images-outside-of-webroot/#findComment-623398 Share on other sites More sharing options...
Psycho Posted August 22, 2008 Share Posted August 22, 2008 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 https://forums.phpfreaks.com/topic/120931-solved-include-images-outside-of-webroot/#findComment-623402 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.