banditda Posted February 27, 2008 Share Posted February 27, 2008 <?phpprint_r(scandir("games"));?> I want it to make a list of all the files in the "games" folder, but it has this error Fatal error: Call to undefined function: scandir() in /home/www/michaelstuff.awardspace.com/index.html on line 2 Link to comment Share on other sites More sharing options...
jhecht Posted February 27, 2008 Share Posted February 27, 2008 if(!function_exists('scandir')){function scandir($dir=false){}}if(!function_exists('scandir')){ function scandir($dir=false,$sort=0){ $dir = ($dir==false) ? dirname(__FILE__) : $dir; //Checks to see if the directory is given, if not, just use the current directory; $dir = (strstr($dir,"*")) ? $dir : $dir."*"; //If the directory contains a *, just leave it alone, if not, append it to the end. $files = glob($dir); $func = ($sort==0) ? 'asort' : 'arsort'; $func($files); return $files; }} Should do it. The error is because the function scandir doesn't exist in your PHP version, whatever it may be. I believe scandir is a PHP 5 only thing, so your host must either be running PHP 4(because they don't feel like upgrading), or your host disabled access to scandir( for some reason unbeknownst to you or I).Take care. Link to comment Share on other sites More sharing options...
banditda Posted February 27, 2008 Author Share Posted February 27, 2008 if(!function_exists('scandir')){function scandir($dir=false){}}if(!function_exists('scandir')){ function scandir($dir=false,$sort=0){ $dir = ($dir==false) ? dirname(__FILE__) : $dir; //Checks to see if the directory is given, if not, just use the current directory; $dir = (strstr($dir,"*")) ? $dir : $dir."*"; //If the directory contains a *, just leave it alone, if not, append it to the end. $files = glob($dir); $func = ($sort==0) ? 'asort' : 'arsort'; $func($files); return $files; }} Should do it. The error is because the function scandir doesn't exist in your PHP version, whatever it may be. I believe scandir is a PHP 5 only thing, so your host must either be running PHP 4(because they don't feel like upgrading), or your host disabled access to scandir( for some reason unbeknownst to you or I).Take care. and i put this after the code? Link to comment Share on other sites More sharing options...
jhecht Posted February 27, 2008 Share Posted February 27, 2008 ... before... Link to comment Share on other sites More sharing options...
Synook Posted February 27, 2008 Share Posted February 27, 2008 That code basically checks whether there is a scandir() function and creates one if there isn't. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 27, 2008 Share Posted February 27, 2008 That code will define a function called scandir that doesn't do anything. Leave out the first part, you only want the second part. if(!function_exists('scandir')){ function scandir($dir=false,$sort=0){ $dir = ($dir==false) ? dirname(__FILE__) : $dir; //Checks to see if the directory is given, if not, just use the current directory; $dir = (strstr($dir,"*")) ? $dir : $dir."*"; //If the directory contains a *, just leave it alone, if not, append it to the end. $files = glob($dir); $func = ($sort==0) ? 'asort' : 'arsort'; $func($files); return $files; }} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.