Issue
I have googled but I can't seem to get my script to work.
this is my code
if (is_dir("tmp")) {
if (substr(sprintf("%o", fileperms("tmp")), -4) == "0777") {
echo "good";
} else {
echo "going to chmod the tmp folder to 777";
if (!chmod("tmp", octdec(0777))) { // tried chmod("tmp, 0777) too
echo "Oops, I couldn't chmod the /setup/tmp directory, please do this manually";
}
}
} else {
echo "we'll make the folder";
}
I can't seem to get the chmod to work, i read somewhere that if register globals was off then this wouldn't work(i have that setting set to off).
I followed the PHP.net manual and some of the examples they provided there in the user comments, as well as some stack-overflow posts that i found relevant. but perhaps i need to tweak some php settings to get this to work?
Is there a way to get the chmod function to work without needing to change the PHP.ini?
Solution
You haven't given us enough information to determine why chmod()
is failing. It could be that the web-server doesn't have sufficient privileges to alter directory permissions.
The owner of the web-server process should own the directory or be a member of the owning group. For example, if root owns tmp, and your web-server is running as the user 'apache', it will not be possible to modify the directory's permissions from PHP.
I believe the settings you mention in php.ini are for debugging, not magically 'fixing' chmod
. Try prepending the following lines of code to your PHP script and you should get more useful debug output:
ini_set('display_errors', 'On');
error_reporting(E_ALL)
Answered By - Rob Answer Checked By - Mary Flores (WPSolving Volunteer)