Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

scandir()

Contributor ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

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
TOPICS
Server side applications

Views

613
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

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/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

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 ?


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

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/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007

Copy link to clipboard

Copied

On Wed, 14 Mar 2007 03:05:47 +0000 (UTC), "LuisDesigns"
<webforumsuser@macromedia.com> wrote:

> http://therainbowpride.com/myphp2/images.php
>
> i can't see what did i do wrong tho.

Your page still seems to be calling the function scandir(). You need
to call your new function instead.
--
Steve Fleischer
steve at flyingtigerwebdesign dot com
Hong Kong

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 13, 2007 Mar 13, 2007

Copy link to clipboard

Copied

i will go and work on it right now, "wish me good luck" lol
Thanks so much for your time

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

LATEST
i got it fix, Steve. Thanks so much for the help.
Apreciate it

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines