Functions: is_dir & is_file doesn't work. Why?

Discussion in 'PHP' started by 11alex11, Mar 30, 2010.

  1. #1
    This is the code:

    $dir = "wallpapers/";
    
    setWatermarkToDir($dir);
    
    function setWatermarkToDir($dir){
    	$dh = opendir($dir);
    	echo "Dir:  $dir <br/>";
    	while (($file = readdir($dh)) !== false) {
    		echo 'Unknown: ' . $file . "<br/>";
    		if(strlen($file) > 2)	{
    			// check to see if it is a file
    			if(is_file($file) == true) {
    				echo "File: $file <br/>";
    				setWatermarkText('Img4u.com',$dir . $file,$dir . $file);
    			}
    			// check if it is a directory
    			if (is_dir($file) == true)	{
    				echo "Opening directory $dir . $file / <br/>";
    				setWatermarkToDir( $dir . $file . '/');
    			}
    		}
    	}
    	closedir($dh);
    }
    PHP:
    what could be the reason for this?

    Also when I read the files in directory the first two is "." and "..", y is that? (This is the reason for strlen > 2)
     
    11alex11, Mar 30, 2010 IP
  2. Nyu

    Nyu Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The . refers to the current directory and the .. to the parent directry of your current directory. And i tried the code and everything runs fine an my server? What errors are you experiening?
    // btw: take a look at scan_dir function. This functions reads a directory and return all items in it as an array so you do not need to read the directory manual and work with file handles ;)
     
    Nyu, Mar 30, 2010 IP
  3. 11alex11

    11alex11 Peon

    Messages:
    113
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks I solved this. THe problem was that is didn't give the full path for the $file in the function
     
    11alex11, Mar 30, 2010 IP