views:

26

answers:

2

Hello everyone,

I am having some trouble with an if, else and is_dir; I am trying to create a small script that tells me if the input is a folder or a file, I have looked at: http://us2.php.net/manual/en/function.is-dir.php for a few examples, and none of them seemed to resemble mine, I read a bit on if and else as well, and it looks like I am doing that right so I think I am not using is_dir the way it is meant to be used. Can someone shed some light on this?

The exact error im getting is:

Parse error: syntax error, unexpected T_ELSE in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dev\test\php\test.php on line 8

Attempt 1:

<?php

$dir = "/some/random/path/on/the/server";

if (is_dir($dir));
 {
  echo "Works!";
 } elseif(!is_dir($dir)); {
  echo "Not good!";
 } 
?>

Attempt 2:

<?php

$dir = "/some/random/path/on/the/server";

if (! is_dir($dir));
 {
  echo "Error\n";
 } else {
  echo "Proceed";
 }

?>

Thank you for your help!

+4  A: 

Remove semicolon after if and elseif statements and you are good to go.

Ondrej Slinták
... after `if` and `elseif` ...
svens
Thank you! this fixed it, that was a fast answer!
imbadatjquery
+3  A: 

You are closing your conditions with ; - thats your problem. You will have to do this:

<?php

$dir = "/some/random/path/on/the/server";

if (is_dir($dir))
{
  echo "Works!";
} elseif( !is_dir($dir) ) 
{
    echo "Not good!";
} 
?>
Repox