Page 1 of 1

scandir() isn't working on hosting server, but works local

Posted: Thu Apr 09, 2009 11:22 pm
by xplore
Heres the hosting url

http://ukanadian.com/genn/listing.php

the error

Fatal error: Call to undefined function: scandir() in /homepages/4/d256007782/htdocs/genn/listing.php on line 13

Heres the code for that page

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Download *BETA*</title>
 
</head>
 
<body>
                <?php
                echo "contents of ".getcwd()."<br />";
                $cur = getcwd();
                $cur = scandir($cur);
                foreach ($cur as $temp) {   
                    
                ?>
            <p>
            <ul>
            <li>
            <a href="<?php echo $temp; ?>"><?php echo $temp; ?></a></li>
            </ul>
            </p>
                <?php
                    
                }
                
                ?>
 
</body>
</html>
 



The purpose of the site is really just to expand my knowledge of PHP so I plan on expanding the complexity of the code to accomplish greater tasks as I progress.


Anyway localhost is displaying the files in the current working dir but on the server its telling me the above error. Any reason as to why?

Re: scandir() isn't working on hosting server, but works local

Posted: Fri Apr 10, 2009 12:56 am
by php_east
scandir is a 'new' addition to the PHP family, coming as at PHP5,
the codes below execute in PHP4, maybe even lower.

Code: Select all

    // For PHP4 compatibility
    //............................................................................................
    function php4_scandir($dir) 
    //............................................................................................
    {
        $dh  = opendir($dir);
        while( false !== ($filename = readdir($dh)) ) 
        {
        if ($filename=='.' OR $filename=='..' ) continue; else $files[] = $filename;
        }
        sort($files);
        return($files);
    }
    //............................................................................................
 
 

Re: scandir() isn't working on hosting server, but works local

Posted: Fri Apr 10, 2009 1:05 am
by xplore
So what you're saying is that the server isn't updated with PHP v5?

Re: scandir() isn't working on hosting server, but works local

Posted: Fri Apr 10, 2009 1:39 am
by corkman
Yup. To see the version of php on the server, upload a simple phpinfo.php to the hosting:

Code: Select all

<?php
phpinfo();
?>