Forum Moderators: coopster

Message Too Old, No Replies

file permissions problem

can't get octal value to trigger else clause?

         

Matthew1980

8:45 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of the forum!

I have this code, just trialling at the moment, but I can't seem to get it to throw the else clause even if I manually change the file permissions. Or is there a better way to check to see if the file permissions fall between a range of octal numbers?

code:-

if(substr(sprintf('%o', fileperms("path/to/file.html")), -4) == "0666" || "0775" || "0776" || "0777"){
echo "file is writeable";
}
else{
echo "file is not writeable";
}

Thanks for any help or suggestions.

Cheers,
MRb

eelixduppy

8:52 pm on Apr 28, 2010 (gmt 0)



There's an easier solution to this :)

[us3.php.net...]

Matthew1980

9:10 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there eelixduppy,

I thought it looked a bit long winded when I was assembling the code ;-p I guess that's the trouble when you have been checking the file permissions manually, you just pop on php.net and type in what comes to mind. I never thought of checking for that.

Cheers, works perfectly now.
MRb

eelixduppy

9:14 pm on Apr 28, 2010 (gmt 0)



Glad to hear it's working now.

Just for future information, you cannot have a condition like you wrote above. What you should have written should follow this format:

if($var == "0666" || $var == "0775" || $var == "0776" || $var == "0777")

Notice how I compare it each time. Otherwise you aren't checking the same thing.

Matthew1980

9:36 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there eelixduppy,

Thanks for the pointer, you have made me wonder now, I am sure I have done something like this recently and it worked fine, but since you point it out it is kinda obvious isn't it.

Ahh, this is similar to what I have done previously, and it functions, (or at least seems to):-

if(isset($_POST['format']) && ($_POST['format'] == "jpg" || "JPG"))

I'm sure as this is valid syntax, the assumption was I think that I could carry on the 'chain' and the same effect would be there.

Again,

Cheers,
MRb

eelixduppy

9:47 pm on Apr 28, 2010 (gmt 0)



That is a valid statement, but it doesn't do what you want. That condition checks three things:

1) If isset($_POST['format']) is TRUE
AND
2) $_POST['format'] == "jpg" is TRUE
OR
3) "JPG" is TRUE

What you really want is this ;)

if(isset($_POST['format']) && strtolower($_POST['format']) == "jpg")

Matthew1980

10:04 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there eelixduppy,

Thanks for the pointers/advice. Sometimes good for another point of view :)

Cheers,
MRb