Alanistic Posted March 29, 2009 Share Posted March 29, 2009 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 More sharing options...
corbin Posted March 29, 2009 Share Posted March 29, 2009 Errrr..... You're using a local file path, when you need to be using one relative to the web root. Link to comment https://forums.phpfreaks.com/topic/151627-displaying-images-in-a-directory/#findComment-796321 Share on other sites More sharing options...
Alanistic Posted March 30, 2009 Author Share Posted March 30, 2009 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> '; } } ?> Link to comment https://forums.phpfreaks.com/topic/151627-displaying-images-in-a-directory/#findComment-797048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.