0

This is the code I'm using to get and display images from a folder on my server:

$root = realpath($_SERVER["DOCUMENT_ROOT"]);
$dirname = "$root/Folder/".$row['city']."/";
$images = glob($dirname."".$row['id']."@*.jpg");
foreach($images as $image) {
echo "<img src=\"".$image."\">";
}

The "normal" path of a picture is /Folder/Berlin/1@1.jpg. In the rendered HTML source code I can see PHP makes this link: /var/www/user_name/html/Folder/Berlin/1@1.jpg

But unfortunately the image doesn't get loaded.

What am I doing wrong?

  • Read http://stackoverflow.com/questions/6546033/whats-the-difference-between-path-and-url-in-ios. If you want to load an image in browser you should build url. – Andrej Aug 28 '16 at 17:31
  • Remove `$root` from `$dirname`, `echo "";` – Hendra Nucleo Aug 28 '16 at 17:33
  • @Hendra Nucleo You mean like this? Code: `$dirname = "/Folder/".$row['city']."/";` `$images = glob($dirname."".$row['id']."@*.jpg");` `foreach($images as $image) {` `echo "";}` –  Aug 28 '16 at 17:44
  • Yes, try................... – Hendra Nucleo Aug 28 '16 at 17:45
  • I get: `Parse error: syntax error, unexpected '$_SERVER' (T_VARIABLE), expecting ',' or ';' in /var/www/username/html/folder_to_actual_php_file/name_of_actual_php_file.php on line 102` –  Aug 28 '16 at 17:47
  • Or `$root = realpath($_SERVER["HTTP_HOST"]);` and use your original code before. – Hendra Nucleo Aug 28 '16 at 18:05
  • Doesn't work, `foreach()` doesn't get executed, stays blank. BTW: Just noticed `echo $images;` only outputs: `Array` –  Aug 28 '16 at 18:12

0 Answers0