Jump to content

Fatal error: Cannot redeclare function


Worqy

Recommended Posts

Here is the code:

// Count files
function filecount($FolderPath) {

    $filescount = 0;
// Open the directory 
    $dir = opendir($FolderPath);
// if the directory doesn't exist  return 0
    if (!$dir){return 0;}
// Read the directory and get the files 
    while (($file = readdir($dir)) !== false) {

        if ($file[0] == '.'){ continue; }

		//if '.' it is a sub folder and call the function recursively
        if (is_dir($FolderPath.$file)){        

            // Call the function if it is a folder type
            $filescount += filecount($FolderPath.$file.DIRECTORY_SEPARATOR);			
        }
        else {
            // Increment the File Count.
            $filescount++;
        }
    }    
    // close the directory
    closedir($dir);
     return $filescount;
}

function getfilenames($location)
{
    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($location);

    // open directory and walk through the filenames
    while ($file = readdir($handler)) {

      // if file isn't this directory or its parent, add it to the results
      if ($file != "." && $file != "..") {
        $results[] = $file;
      }

    }

    // tidy up: close the handler
    closedir($handler);
    // done!
    return $results;
}

function readfile($file)
{

$fh = fopen('./Data/' . $file, 'r');
$data = fread($fh, filesize($file));
fclose($fh);
return $data;
}

 

Now, when I try to get the text from a textfile via the function readfile I get this error:

Fatal error: Cannot redeclare readfile() in ***Path\FileManagement.php on line 62

 

Whats wrong?

 

Regards

Worqy

Link to comment
https://forums.phpfreaks.com/topic/226867-fatal-error-cannot-redeclare-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.