Jump to content

Displaying Images In A Directory


Alanistic

Recommended Posts

Hello all.

 

I'm looking for a bit of help.  I'm a basic PHP user and I know I'm missing something really simple and stupid.  I've got some code (below) which searches through a directory and returns all files in there.  It successfully returns the file path of the image, but not the image itself. 

 

What am I doing wrong?

 

<?php

 

$dir="C:\\xampp\\htdocs\\Photos\\";

 

$handle = opendir ($dir);

while (false !== ($file = readdir($handle))) {

$filepath = $dir.$file;

echo $filepath;

        echo '<br><img src="'.$filepath.'"/><p>';

    }

?>

Link to comment
https://forums.phpfreaks.com/topic/151627-displaying-images-in-a-directory/
Share on other sites

Thanks, that was such a stupid mistake to make.

 

I've almost got what I'm looking for just now.  I have images in a specific folder that are all being listed and I also have a txt file which is being ignored.  The txt file is then opened and the contents displayed on screen.  Can anyone tell me why the contents of my txt file are being added to the page after the images when the code is executed first?? 

 

<?php

 

$dir="./Photos/LA/";

 

$handle = opendir ($dir);

echo '<div align="left">';

while (false !== ($file = readdir($handle))) {

$filepath = $dir.$file;

if($file == "info.txt") {

$array = file($filepath);

echo '<strong><font color="#5A91AB" size="2" face="Arial, Helvetica, sans-serif">'.$array[0].'</font></strong><br>';

echo '<font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif">'.$array[1].'</font><p>';

}

if($file != "." && $file != ".." && $file != "title.jpg" && $file != "TITLE.jpg" && $file != "info.txt") {

$filepath = $dir.$file;

#echo $filepath;

echo ' <a href="'.$filepath.'" target="_blank"><img src="'.$filepath.'" width="138" height="104" border="0"></a> ';

}

    }

?>

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.