Jump to content

Help including files outside of web/public_html folders


Paulio

Recommended Posts

Hey, on my readynas duo i have a share called movies, inside the movies share there are hundreds of subdirectories each with a movie file (mostly avi), a txt file (Details.txt) and an image (cover.jpg)

 

i am trying to list the contents using a php script, so far i can get the info from the text file but not the image as its not in my web share...

 

Here is what i have:

 

<?

$MovieDir = "/c/Movies/The.Taking.of.Pelham.1.2.3[2009]/";

$DetailsFile = $MovieDir . "Details.txt";

$CoverFile = $MovieDir . "cover.jpg";

 

$fh = fopen($DetailsFile, 'r');

$theData = fread($fh, filesize($DetailsFile));

fclose($fh);

$delimiter ="@";

list($title, $year, $genre, $plot, $tag, $imdb, $created) = explode($delimiter, $theData);

 

 

echo "<table border='1'><tr><td>";

echo "<b>Title:</b> $title<br>";

echo "<b>Year:</b> $year<br>";

echo "<b>Genre:</b> $genre<br>";

echo "<b>Plot:</b> $plot<br>";

echo "<b>Tagline:</b> $tag<br>";

echo "<b>IMDb:</b> $imdb<br>";

echo "<b>Created:</b> $created<br>";

echo "</td><tr>";

echo "<img src='" . $CoverFile . "></tr</td></table>";

//echo $theData;

?>

 

Obviously the last image tag is incorrect but you can see what i am trying to acomplish by what i have typed there, is there a function in php that will alow me to include it/load it into a variable etc... for use as the web path is "/c/web..." and the movies are in "/c/movies..." etc...

 

 

Thanks, Paul.

You can't display an image that is not within your webroot. What you need to do, is to write a script that will fetch a file from this location, and send it to browser with aprropriate headers, like:

 

<?php
$MovieDir = "/c/Movies/The.Taking.of.Pelham.1.2.3[2009]/";
$CoverFile = $MovieDir . "cover.jpg";
header('Content-type: image/jpg');
readfile($CoverFile);
?>

save it as picture.php

Then in your main script use

 

echo "<img src='picture.php'></tr></td></table>";

 

 

You can't display an image that is not within your webroot. What you need to do, is to write a script that will fetch a file from this location, and send it to browser with aprropriate headers, like:

 

<?php
$MovieDir = "/c/Movies/The.Taking.of.Pelham.1.2.3[2009]/";
$CoverFile = $MovieDir . "cover.jpg";
header('Content-type: image/jpg');
readfile($CoverFile);
?>

save it as picture.php

Then in your main script use

 

echo "<img src='picture.php'></tr></td></table>";

 

 

 

This is exactly what ive been looking for!!

 

Thanks!

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.