Page 1 of 1

specifying pathe for filesystem commands

Posted: Fri Jan 03, 2003 3:59 am
by justravis
Consider these paths:
~/www/admin/webmaster/file_cmds.php
~/www/content/

I'm trying to use rmdir() & exec(), in file_cmds.php to manipulate files & folders in the content dir. It's not working. I can only manipulate files in the same dir as the script.

How should I specify the path?

Failed attempts:
~/www/content/
/home/user/www/content/

Here is an example of code i'm using:

Code: Select all

<?php

    if(file_exists($dir))
    {
        #@ prevents from errors being outputted when rmdir() fails.
        $emptydir=@rmdir("$dir");

        if(!$emptydir)
        {
            exec("rm -r $dir");
        }
    }

?>

Posted: Fri Jan 03, 2003 5:28 am
by Elmseeker
Don't use relative path's use full path's to your files, try changing:

~/www/admin/webmaster/file_cmds.php
~/www/content/

to:

/full/path/to/www/admin/webmaster/file_cmds.php
/full/path/to/www/content/

Posted: Fri Jan 03, 2003 8:11 am
by Johnm
Also, ensure that the webserver has the proper permissions to do that too.


John M

Posted: Fri Jan 03, 2003 12:18 pm
by justravis
If the webserver was not configured properly, would the scripts even manipulate files and folders in it's own dir?

problem lies in functions returning fals

Posted: Fri Jan 03, 2003 1:27 pm
by justravis
Isolated problem...functions execute, but the functions still return false. Any ideas why?

I have error messages that print out for these scenarios:

Code: Select all

<?php
$mkdirsuccess=dircreate($pardir, $newdir);
$deldirsuccess= dirdel($dir);

if(!$mkdirsuccess)
{
     echo error;
}
if(!$deldirsuccess)
{
     echo error;
}
?>
Here are my functions:

Code: Select all

#Creates directories if they do not exist & changes thier permissions if they do.
function dircreate($pardir, $newdir)
{
        $ogmask=umask(0);

        if(!file_exists("$pardir/$newdir"))
        {
                $mkdirsuccess=mkdir("$pardir/$newdir", 0777);

                return $mkdirsuccess;
        }
        else
        {
                $chgpermssuccess=chmod("$pardir/$newdir", 0777);

                $chgpermssuccess;
        }

        $newmask=umask($ogmask);
}

#Deletes directories empty or not.
#If directory does not exist, it still returns true.
function dirdel($dir)
{
        if(file_exists($dir))
        {
                #@ prevents from errors being outputted when rmdir() fails.
                $emptydir=@rmdir($dir);

                if(!$emptydir)
                {
                        $execsuccess=exec("rm -rf $dir");

                        return $execsuccess;
                }
                else
                {
                        return $emptydir;
                }
        }
        else
        {
                $alreadydel++;

                return $alreadydel;
        }
}

PROBLEM SOLVED

Posted: Sat Jan 04, 2003 11:57 am
by justravis
Yesterday I isolated the problem even further to the chmod portion of the direcreate() function. If the folder already exists, the function is supposed to ensure the folder has the correct permissions.

I spent eternity trying to prove my theory that chmod() returns false if the folder is already the permissions you are trying to set. WHY ELSE WOULD THE CHMOD PORTION RETURN FALSE???

Well I found the answer to that question when I finally decided to refer back to the dircreate() function:

Code: Select all

<?php
else 
        { 
                $chgpermssuccess=chmod("$pardir/$newdir", 0777); 

                $chgpermssuccess; 
        } 
?>
"$chgpermssuccess;" SHOULD BE "return $chgpermssuccess;"

HMMM>>>MAYBE THAT IT IS WHY IT WAS RETURNING FALSE

DUHHH

PROBLEM SOLVED

Posted: Sat Jan 04, 2003 12:00 pm
by justravis
Yesterday I isolated the problem even further to the chmod portion of the direcreate() function. If the folder already exists, the function is supposed to ensure the folder has the correct permissions.

I spent eternity trying to prove my theory that chmod() returns false if the folder is already the permissions you are trying to set. WHY ELSE WOULD THE CHMOD PORTION RETURN FALSE???

Well I found the answer to that question when I finally decided to refer back to the dircreate() function:

Code: Select all

<?php
else 
        { 
                $chgpermssuccess=chmod("$pardir/$newdir", 0777); 

                $chgpermssuccess; 
        } 
?>
"$chgpermssuccess;" SHOULD BE "return $chgpermssuccess;"

HMMM>>>MAYBE THAT IT IS WHY IT WAS RETURNING FALSE

DUHHH

Anyway, I thought I would be courteous enough to post the solution found. Even if it was just an oversight on my part. You never know if someone may refer to this for an answer to a similar problem.