Jump to content

[SOLVED] readdir/closedir error


Bramme

Recommended Posts

Okay, this is bugging me.

 

I've written a small class, extending Smarty and I want to go through a folder, checking the files in it.

 

Now I wrote the code first in line, to see if it worked and then converted it to a function in my class (seeing as I'm kinda new to OO and I was merely experimenting).

 

Now I'm getting two warnings, resulting in my script actually not working:

Warning: readdir(): supplied argument is not a valid Directory resource

Warning: closedir(): supplied argument is not a valid Directory resource

Here's my code.

<?php
require(ROOT.'/libs/Smarty.class.php');

class Modular extends Smarty {

var $modulesDir = null;
var $uModules = array();

//Construct function, starting Smarty 
public function __construct() {

	$this->modulesDir = ROOT.'/admin/mods/';
	$this->config_dir = ROOT.'/libs/configs/';
}

public function getModules() {
	if ($handle = opendir($this->modulesDir) || die("Could not open Modules directory")) {
		while ($file = readdir($handle) !== false) {
			if($file != "." && $file != ".." && !is_dir($this->modulesDir.$file)) {

				$Module = fopen($this->modulesDir.$file, 'r');
				$modContent = fread($Module, 26);
				fclose($Module);


				$this->uModules[] = $file;
			}
		}
		closedir($handle);
	}
	return $this->uModules;
}

/* end class */}
?>

First I thought it had something to do with safemode being on, but my host turned it off and it hasn't changed...

 

Damn, i changed it back to how i started off, putting the code directly into index.php, not using a function, but the problem persists.

Posting in the general php help area too...

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.