View Full Version : check chmod.. with PHP
sWo0p
July 19th, 2005, 05:58 AM
i already know how to change chmod but is there anyway to check chmod of a filename or dir.. ???
hl
July 19th, 2005, 06:16 AM
i don't think so.
however, you can change the permissions of a file using PHP. www.php.net/chmod
if your working on an application and require people to chmod, which is the situation i'm picturing, that's the best way to do it.
sWo0p
July 19th, 2005, 07:19 AM
no im woriking on a check script that checks if the instalation has bin done correctly.. and some of my files need to be a chmod 777 and some need to be 644..
i want a listing that shows if the key files are correctly chmoded
hl
July 19th, 2005, 08:00 AM
no im woriking on a check script that checks if the instalation has bin done correctly.. and some of my files need to be a chmod 777 and some need to be 644..
i want a listing that shows if the key files are correctly chmoded
that's what i assumed ;). what i meant was that you can use that to chmod it instead of having the user do it.
i can't think of a way to get a files permissions, i'll look out for it :)
Yeldarb
July 19th, 2005, 09:18 AM
If you have access to the PHP permissions, allow access to the console from your script (I think it's in your PHP.ini) and then just do a
`ls -l <yourFile>`
I've never done it before so I don't remember the syntax or how to enable it in PHP, but I am pretty sure it's possible to run commands via PHP.
Sniper Jo
July 19th, 2005, 01:45 PM
If you only want to check that the file is writeable you can use
<?php
$filename = 'test.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
?>
jerez_z
July 19th, 2005, 02:06 PM
If you only want to check that the file is writeable you can use
<?php
$filename = 'test.txt';
if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
?> thats a good idea. Nice thought
EDIT: I found this code in the comments on the PHP chmod site:
When using ftp_rawlist, in order to get the chmod number from the attributes, i use this code:
function chmodnum($mode) {
$realmode = "";
$legal = array("","w","r","x","-");
$attarray = preg_split("//",$mode);
for($i=0;$i<count($attarray);$i++){
if($key = array_search($attarray[$i],$legal)){
$realmode .= $legal[$key];
}
}
$mode = str_pad($realmode,9,'-');
$trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
$mode = strtr($mode,$trans);
$newmode = '';
$newmode .= $mode[0]+$mode[1]+$mode[2];
$newmode .= $mode[3]+$mode[4]+$mode[5];
$newmode .= $mode[6]+$mode[7]+$mode[8];
return $newmode;
}
funny thing, the email it was posted by was info[at]rvgate[dot]nl :puzzled:
sWo0p
July 20th, 2005, 02:30 AM
well lets not go to deep in detail i just want to know if that file is writable.. so i think the if() script of sniper wil do perfectly.. but i'll keep both script in my collection.. you never know when it gets handy..
PS, Jerez what do you neem??? "funny thing, the email it was posted by was info[at]rvgate[dot]nl"
hl
July 20th, 2005, 07:17 AM
well lets not go to deep in detail i just want to know if that file is writable.. so i think the if() script of sniper wil do perfectly.. but i'll keep both script in my collection.. you never know when it gets handy..
PS, Jerez what do you neem??? "funny thing, the email it was posted by was info[at]rvgate[dot]nl"
rvgate is a member at the forums here. he's a pretty kick *** scripter.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.