Skip to main content
Inspiring
March 13, 2007
Question

scandir()

  • March 13, 2007
  • 5 replies
  • 691 views
i have this script that uses Scandir(), which apparently is used in the newer version of php that i am using "php5" .

this is the code : -- and i get this error

Fatal error: Call to undefined function: scandir() in /home/therainb/public_html/myphp2/images.php on line 47



$dir = 'uploads'; // Define the directory to view.

$files = scandir($dir); // Read all the images into an array. THIS IS MY LINE 47

// Display each image caption as a linkto the javaScript function.
foreach ($files as $image) {

if (substr($image, 0, 1) != '.') { // Ignore anything starting with a period.

// Get the image's size in pixels.
$image_size = getimagesize("$dir/$image");


What do i need to replace instead of scandir() guys ?

thank you again
This topic has been closed for replies.

5 replies

Inspiring
March 15, 2007
i got it fix, Steve. Thanks so much for the help.
Apreciate it
Inspiring
March 14, 2007
i will go and work on it right now, "wish me good luck" lol
Thanks so much for your time
Inspiring
March 13, 2007
LuisDesigns wrote:
> i clicked the link and i am a lil confused, i am sorry . What would i need to put in to replace scandir() ?
> would i use opendir($dir) instead ?

On that page, example 486 shows you how to do something with scandir();
example 487 shows you how to do the same with PHP 4 functions using
opendir(). Lower down the page is a link to opendir(), which gives you
more information on how opendir() works.

At the moment, Luis, your problem seems to be that you're looking for
"the answer" to specific problems. Occasionally, you'll find exactly
what you're looking for, but the real value of working with a language
like PHP is that it lets you create your own solutions.

Test the scandir() example. Test the opendir() example. See where
they're similar. See where they're different. Try the examples on the
opendir() page. It's like learning to walk. It takes lots of practice,
but then suddenly it all comes together.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
March 14, 2007
ok, i have changed the scandir() to this :

<?php # Script 11.2 - images.php
// This script lists the images in the uploads directory.

$dir = 'uploads'; // Define the directory to view.

function php4_scandir($dir,$listDirectories=false, $skipDots=true) {
$dirArray = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (($file != "." && $file != "..") || $skipDots == true) {
if($listDirectories == false) { if(is_dir($file)) { continue; } }
array_push($dirArray,basename($file));
}
}
closedir($handle);
}
return $dirArray;
}

if (substr($image, 0, 1) != '.') { // Ignore anything starting with a period.

// Get the image's size in pixels.
$image_size = getimagesize("$dir/$image");

// Calculate the image's size in kilobytes.
$file_size = round ( (filesize("$dir/$image")) / 1024) . "kb";

// Print the information.
echo " <tr>
<td><a href=\"javascript: create_window('image', $image_size[0],$image_size[1])\">$image</a></td>
<td>$file_size</td>
</tr>";

} // End of the IF.

// End of the foreach loop.
?>

and this is what i am getting :

http://therainbowpride.com/myphp2/images.php

i can't see what did i do wrong tho.
Inspiring
March 13, 2007
i clicked the link and i am a lil confused, i am sorry . What would i need to put in to replace scandir() ?
would i use opendir($dir) instead ?


Inspiring
March 13, 2007
LuisDesigns wrote:
> What do i need to replace instead of scandir() guys ?

Learn to use the PHP online manual. If you look up scandir(), it shows
you how to do the same thing with PHP 4 functions:

http://www.php.net/manual/en/function.scandir.php

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/