Forum Moderators: coopster

Message Too Old, No Replies

syntax error?

image directory file

         

russgri

10:52 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



I have a file called index.php and I place it on my server in the image directory.
It is supposed to display all the images in the directory.

<?
$NAMEFILE = "index.php"; //This files name.
$dir = opendir("./images"); //Replace the dot with ./yourfolder or leave it as it is.
while ($file = readdir($dir)) {
if ($file!= "." && $file!= ".." && $file!= "$NAMEFILE") {
$time = filemtime("$file");
$data[$time] = "<a href=\"$file\" target=\"new\"><img src=\"$file\" border=\"0\" bordercolor=\"black\" width=\"50\" height=\"50\"></a>
";
}}
krsort($data);
while(list($k,$v) = each($data)) { echo $v; }
clearstatcache();
echo "<br />";
?>

I get this error

Warning: opendir(./images): failed to open dir: No such file or directory in /home/user/public_html/images/index.php on line 3

Warning: readdir(): supplied argument is not a valid Directory resource in /home/user/public_html/images/index.php on line 4

Warning: krsort() expects parameter 1 to be array, null given in /home/user/public_html/images/index.php on line 11

Warning: Variable passed to each() is not an array or object in /home/user/public_html/images/index.php on line 12

I have a file called index.php and I place it on my server in the image directory.
It is supposed to display all the images in the directory.

<?
$NAMEFILE = "index.php"; //This files name.
$dir = opendir("./images"); //Replace the dot with ./yourfolder or leave it as it is.
while ($file = readdir($dir)) {
if ($file!= "." && $file!= ".." && $file!= "$NAMEFILE") {
$time = filemtime("$file");
$data[$time] = "<a href=\"$file\" target=\"new\"><img src=\"$file\" border=\"0\" bordercolor=\"black\" width=\"50\" height=\"50\"></a>
";
}}
krsort($data);
while(list($k,$v) = each($data)) { echo $v; }
clearstatcache();
echo "<br />";
?>
I get this error

Warning: opendir(./images): failed to open dir: No such file or directory in /home/user/public_html/images/index.php on line 3
Warning: readdir(): supplied argument is not a valid Directory resource in /home/user/public_html/images/index.php on line 4

Warning: krsort() expects parameter 1 to be array, null given in /home/user/public_html/images/index.php on line 11

Warning: Variable passed to each() is not an array or object in /home/user/public_html/images/index.php on line 12

I have a file called index.php and I place it on my server in the image directory.
It is supposed to display all the images in the directory.

<?
$NAMEFILE = "index.php"; //This files name.
$dir = opendir("./images"); //Replace the dot with ./yourfolder or leave it as it is.
while ($file = readdir($dir)) {
if ($file!= "." && $file!= ".." && $file!= "$NAMEFILE") {
$time = filemtime("$file");
$data[$time] = "<a href=\"$file\" target=\"new\"><img src=\"$file\" border=\"0\" bordercolor=\"black\" width=\"50\" height=\"50\"></a>
";
}}
krsort($data);
while(list($k,$v) = each($data)) { echo $v; }
clearstatcache();
echo "<br />";
?>
I get this error

Warning: opendir(./images): failed to open dir: No such file or directory in /home/user/public_html/images/index.php on line 3
Warning: readdir(): supplied argument is not a valid Directory resource in /home/user/public_html/images/index.php on line 4

Warning: krsort() expects parameter 1 to be array, null given in /home/user/public_html/images/index.php on line 11

Warning: Variable passed to each() is not an array or object in /home/user/public_html/images/index.php on line 12

What say ye?

justageek

10:57 pm on Jan 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you are already in the directory so replace:

$dir = opendir("./images");

with:

$dir = opendir(".");

JAG