Jump to content

[SOLVED] unreachable statement


muckv

Recommended Posts

function make_thumb_dir($path){

$resource_path = opendir($path) or die('Dir openen gaat niet');

      while (($filename = readdir($resource_path)) != false) {
          if (is_dir($filename) && $filename =! '.'&& $filename =! '..') {
          	$img =	get_images_in_dir($filename);
          	
           }
       }

     closedir($resource_path);	


}

 

I never get through to $img = get_images_in_dir($filename);

 

He checks the $filenames in the if but never executes $img = get_images_in_dir($filename);

 

and the $filename is a directory?

 

Could you guys help me out?

Link to comment
https://forums.phpfreaks.com/topic/129380-solved-unreachable-statement/
Share on other sites

Well yeah, it works for me too, but he does'nt execute the next line.

 

So it goe like this

 

$filename = string '.' so do'nt go into the if

NEXT

$filename = string '..' so do'nt go into the if

NEXT

 

$filename = string 'bram' since bram is a directory he should proceed with the code in the if statement right? well it doesn't instead it goes to the next $filename

NEXT

 

$filename = string 'jan' same as above

NEXT

 

$filename = string 'suzy' same as above, end of function

NEXT

function get_images_in_dir($validpath)
{
   

    $files = scandir($validpath);

    for($i = 0;$i < sizeof($files);$i++) {
       $ext  = substr($files[$i], strrpos($files[$i], '.') + 1);

        if(check_extensie($ext)){
    
    		return $files[$i];
        }
        
        
    }

   
}

forget all the code before and look at this

function check_for_dir($path){

$resource_path = opendir($path) or die('Dir openen gaat niet');

      while (($filename = readdir($resource_path)) != false) {
          if (is_dir($filename)) {
          		echo $filename;
          
           }
       }

     closedir($resource_path);	


}

 

tough there are 3 dirs in the given path

the output is ...

he evaluates the 3 dirs as NO dirs in is_dir()

 

 

I had to prepend the working dir.

 

function check_for_dir($path){

$resource_path = opendir($path) or die('Dir openen gaat niet');

      while (($filename = readdir($resource_path)) != false) {
          if (is_dir('./main'$filename)) {
                echo $filename;
         
           }
       }

     closedir($resource_path);   
   
   
}

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.