Hi, I'm creating a small file manager. I started with the directory creation script. I couldn't make it work with the FTP commands (which are less secure anyway if I understanbd correctly...)

I have one page/script which creates directories and another to browse them. At the core of the directory creation is the following:

$old_umask = umask(0);
mkdir($newdir, 0777);
chmod($newdir, 0755);

(this is preceeded by a line which updates my databse with the new directory info)

In the file browser page/script, the code brings up the list of directories. If I manually create a dir via my ftp client, the directory browser opens it without a hitch. But when I attempt to access the directories created with the script above, I get this error:

Warning: opendir(): SAFE MODE Restriction in effect. The script whose uid is 789 is not allowed to access [..path..] owned by uid 48 in [..path..browse.php] on line 22

the error refers to this line of code:
$open = opendir($currentpath);
where $currentpath refers to the newdir in this instance.

Is there a way I could access the script created directories? Is it simply a matter of chmod?
There is this other thread regarding this same problem but I'm also facing the SAFE MODE restiction issue.
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10263494&highlight=opendir

    No, it's not a chmod issue. Read the articles in that other thread...

    Here's some more reading for you:
    http://www.php.net/manual/en/features.safe-mode.functions.php

    It's kind of strange that you're actually able to create the dir... since mkdir is restricted by safe mode as well.

    Why are you running in safe mode anyway? If it's something enforced by your host, get a different host.

      It's kind of strange that you're actually able to create the dir... since mkdir is restricted by safe mode as well.
      Why are you running in safe mode anyway? If it's something enforced by your host, get a different host. [/B]

      Not only can I mkdir but I just found that I can also rmdir! So I'm really mystified about this.

      Regarding safe mode, I took another look at my phpinfo() and I see there are two sets of parameters: local and master.

      Safe mode for local is on while safe mode for master if off.

      Does this mean I can change it? If so, how?

      Thanks!

        I looked up the documentation and it seems I would need "safe_mode_gid" to be switched on.

        I have to figure out how to do this. If local/master means that I can change the options localy, how do I go about this?

          Or you can override the restriction by using your absolute path

          i.e.

          /home/username/public_html/$dirpath

            Originally posted by Kudose
            Or you can override the restriction by using your absolute path



            I should have mentioned it, I am using the absolute path... 😕

              I simply cannot change the safe mode parameters on the shared hosting I'm using. From my host FAQ:

              * File uploads. Files can only be uploaded to directories underneath your web server's root html directory. Furthermore, the permissions on any directory you want to use for uploading files must be set to 777.
              * File modifications: moving, copying and changing ownership/permissions of files can only be done when they are owned by the administrative user.
              * System Commands: PHP scripts running in safe mode cannot use the exec() and system() functions.

              So going back to my problem, something is still unclear and it should have anything to do with the safe mode restrictions. Why would opendir imply different ownership if it's executed by the same source?

                Here's an update in case anyone else had this problem.

                Someone offered me this solution:
                The work-around is to create the directory outside of your web application
                from your regular account. Or if you are allowed to run cgi scripts and
                these are set up via cgiwrapper or suExec to run as your own user id, use
                this to create the directory. Once created with the right owner, you can
                manipulate it from your regular Apache-embedded PHP scripts.

                But by the time I got this, I went back to my attempts at making this work with the FTP functions and that settled the question. The reason why that option wasn't initialy working was because I was using the wrong path in my script. Instead of using the one displayed via http (/home/virtual/site...) I should have been using the one from (surprise, surprise) ftp: (var/www/html/...)

                I hope this information might help others.

                  Write a Reply...