I want to display all the images that are stored outside my web root folder. Please help me. I can only display one image. For example, if I have 5 images in my folder, only one image is displayed 5 times in my browser. Please help me with this. I have been working on this issue for over a month now. I'm a newbie. Help. Thank. Here is the code I'm using.
images.php
<?php
require("includes/copta.php");
$sql = "select * from people";
$result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
$imgLocation = " /uploadfile/";
while ($row = mysql_fetch_array($result))
{
$imgName = $row["filename"];
$imgPath = $imgLocation . $imgName;
echo "<img src=\"call_images.php?imgPath=" . $imgName . "\" alt=\"\"><br/>";
echo $row['id'] . " " . $imgName. "<br />";
}
?>
call_images.php
<?php
require("includes/copta.php");
$imgLocation = '/ uploadz/';
$sql = "select * from people";
$result = mysql_query($sql) or
die ("Could not access DB: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
$imgName = $row["filename"];
$imgPath = $imgLocation . $imgName;
if(!file_exists($imgPath) || !is_file($imgPath)) {
header('HTTP/1.0 404 Not Found');
die('The file does not exist');
}
$imgData = getimagesize($imgPath);
if(!$imgData) {
header('HTTP/1.0 403 Forbidden');
die('The file you requested is not an image.');
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: image/jpg");
header("Content-length: " . filesize($imgPath));
readfile($imgPath);
exit();
}
?>
source
share