We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    does anybody know why the code below is not working? thank you

    <?php
    class FileHandler {
    
    	
    	var $files = array();
    	var $dirs  = array();
    		
    	function getFileItems($path) {
    		//global $files, $dirs, $total_files, $total_dirs;
    		/*$files = array();
    		$dirs = array();*/
    		//$total_files = 0;
    		//$total_dirs = 0;
    		if ($handle = opendir($path)) {
    			while (false !== ($file = readdir($handle))) {
    				if ($file != "." && $file != "..") {
    					
    						if (is_file($path."/".$file)) {
    							$files[] = $file;
    							//$total_files++;
    						} else {
    							$dirs[] = $file;
    							//$total_dirs++;
    						}
    					}
    				
    			}
    		} else {
    			echo "error";
    			return false;
    		}
    		
    		@closedir($handle);
    		return true;		
    	}
    }
    	$fileHandler = new FileHandler();	
    	$path = '../files';
    	$fileHandler->getFileItems($path);
    	
    		
    	foreach($fileHandler->dirs as $item) { 
       		echo $item."<br />"; 
    	}
    
    
    	
    ?>
    
      • 1764
      • 680 Posts
      It looks like
      $dirs[] = $file;

      should be
      $this->dirs[] = $file;


      Are you getting any error at all?
        • 19889
        • 616 Posts
        I’m not getting any errors - just a blank white page - if I echo the array value within it’s function, I’m having some values?!
          • 19889
          • 616 Posts
          this did it - $this->dirs[] = $file; - you were right - thank you