Tuesday, August 12, 2008
Alternative solution for scandir() function in PHP 4
In PHP 5 there is a new function scandir() which lists files and directories inside a path. In this case if you install your script, in a PHP 4 server, which uses scandir() function, then you will notice following error message:
Call to undefined function: scandir()
To solve this problem just add following code in your function page. This will make your script available in both PHP 4 & PHP 5 server.
if(!function_exists('scandir')) {
function scandir($folder) {
$handle = opendir($folder);
while (false !== ($filename = readdir($handle))) {
$files[] = $filename;
}
return $files;
}
}
Posted by Zakaria Chowdhury at 6:02 PM
Subscribe to:
Posts (Atom)