jderosa3
Member
Posted 3 years ago #
I would like to use a simple PHP script to show all of the images in a directory
<?php
$handle = opendir ('http://www.xxx.com/flash/portfolio/branding/images/');
while (false !== ($file = readdir($handle))) {
echo '<img src="'.$file.'"/><br />'.$file.'<br />';
}
?>
This throws back a couple of errors:
Warning opendir(http://www.xxx.com/flash/portfolio/branding/images/)
[function.opendir]: failed to open dir: not implimented in.... "location of exec-php plugin"
Any ideas how to get a simple script like this to work?
Well, writing it so that it's not broken code would be a good start.
The PHP command opendir is trying to open a directory up for reading. However, instead of giving it a directory, you gave it a URL. I wouldn't expect that to actually work because a URL is not a directory.
jderosa3
Member
Posted 3 years ago #
I have tried changing
this:
<?php
$handle = opendir ('http://www.xxx.com/flash/portfolio/branding/images/');
while (false !== ($file = readdir($handle))) {
echo '<img src="'.$file.'"/>'.$file.'';
}
?>
to this:
<?php
$handle = opendir ('../flash/portfolio/branding/images/');
while (false !== ($file = readdir($handle))) {
echo '<img src="'.$file.'"/>'.$file.'';
}
?>
No luck.. is there a javascript snippet that does what I want?
These above still cause errors with the exec-PHP plugin... not sure what going on...
jderosa3
Member
Posted 3 years ago #
Ok... I finally have it reading file onto the page, but... they come up with broken icons as if the graphics are not there... here is my new code:
<?php
$dir = "./flash/portfolio/branding/images/";
//open dir
if ($opendir = opendir($dir))
{
//read dir
while (($file = readdir($opendir)) !== FALSE)
{
if ($file!="."&&$file!="..")
echo $file."<img src='$dir/$file'><br />";
}
}
?>
Any ideas?
jderosa3
Member
Posted 3 years ago #
got it to work! Incase anyone needs to know how to do this:
<?php
$dir = "./flash/portfolio/branding/images/";
$jpgs = glob($dir . "*.jpg");
foreach ($jpgs as $jpg) {
$jpg = substr($jpg, 1);
echo "<img src='http://www.mydomain.com{$jpg}' /><br />";
}
?>