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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.