I've got a script that I'm trying to use to create a directory with the mkdir() command. This command is not working for me. I've verified that the script is running as a user with write and read access. I've verified that the parent directory is readable and writeable. As yet, I am still unable to get my script to work properly.

This is my first time writing a PHP script to make use of filesystem commands, so I'm something of a newbie to the mkdir command. What are some things that can cause the mkdir command to fail? I'll try anything listed here to see if it's what I'm not doing correctly.

My site is hosted with Bluedomino. It is not on a dedicated server. I've emailed them to see if they're running anything that could keep this command from working properly and await their response on Monday.

Thanks,

-Nij

    Hey. I had this same problem a few months ago when i was working with mkdir(). The problem turned out to be with the CHMOD statement. My PHP book (Professional PHP4) used this sample code:

    mkdir ("c:/temp/test", "0700");

    Which was not working for me. After some messing around i changed it to this and it worked.

    mkdir ("c:/temp/test", 0700);

    Not sure what the problem is, and wether this is your problem, but thats one bug i ran into.

      Originally posted by nova
      Hey. I had this same problem a few months ago when i was working with mkdir(). The problem turned out to be with the CHMOD statement. My PHP book (Professional PHP4) used this sample code:

      mkdir ("c:/temp/test", "0700");

      Which was not working for me. After some messing around i changed it to this and it worked.

      mkdir ("c:/temp/test", 0700);

      Not sure what the problem is, and wether this is your problem, but thats one bug i ran into. [/B]

      Thanksfor your advice. I'm not enclosing my permissions integer in quotations, so that isn't the problem.

      -Nij

        Could you post your code snip?

          That looks right to me. If you are sure your folders CHMOD allows writing, i see nothing wrong with this.

            Yeah, which is why I was wondering if there were other factors that could cause it to fail, ones that I was not aware of, perhaps (and I'll be the first to admit, that could be quite a few).

            -Nij

              with windows CHMOD dose not work or have an effect on files

                I've been having a similar problem. (chmod files) I believe the server can either enable or disable chmoding files, so that is probably your problem.

                  Originally posted by pyro
                  I've been having a similar problem. (chmod files) I believe the server can either enable or disable chmoding files, so that is probably your problem.

                  I don't think this is the problem; PHP 4.2.2 (which my server is running) allows the use of mkdir without including a chmod integer, and mkdir still won't work if I do this. Nevertheless, what's an effective way that I could test to see whether chmod does or does not work on my server, and if it doesn't, how could I get around that to make mkdir work properly?

                  Thanks again.

                  -Nij

                    Here's how you can check if CHMOD works...

                    <?PHP
                    chmod ("test.txt", 0666);
                    ?>

                    and then check to see if the file test.txt is chmoded to 666

                    $chmodvalue = decoct(fileperms("test.txt"));
                    $substring = substr($chmodvalue,strlen($chmodvalue)-4,strlen($chmodvalue)); 
                    echo ("$substring");

                      Thanks.

                      This code returns value "0644".

                      -Nij

                        Then, it would appear that chmod is disabled. It should have chmoded your file to 666, so it should have returned 0666, rather than the default of 0644. Talk to your system administrator, I think it is something that can be enabled or disabled. I had to have my sys admin work on it... Still waiting. 🙂

                          Originally posted by pyro
                          Then, it would appear that chmod is disabled. It should have chmoded your file to 666, so it should have returned 0666, rather than the default of 0644. Talk to your system administrator, I think it is something that can be enabled or disabled. I had to have my sys admin work on it... Still waiting. 🙂

                          Well, thanks a lot. Whether or not this fixes my problem, this is very helpful. I'm grateful for your help, sir.

                          -Nij

                            The file has to be owned by the user that the webserver runs as, or have higher permissions to begin with.

                            If any user could chmod any files then hosts would never be able to secure their systems. Any user could use php to chmod 777 /etc/passwd and view a list of the users.

                            You need to chown -R nobody.nobody <path> in order to change the owner. And then chmod is not even needed.

                            If you can convince the admin of your server to turn safe_mode off, that may relieve some stress, but as it implies, its no longer in safe_mode then. ( Might want to research this, I heard this, but not 100% sure. )

                              You need to chown -R nobody.nobody <path> in order to change the owner. And then chmod is not even needed.

                              I'm not sure what you mean. I can't use chown because I'm not the superuser-- my scripts are running on a shared server. My scripts do run as me, a user that has read/write control and can create directories when I FTP to the server; but for some reason mkdir will not work in my scripts.

                              If you can convince the admin of your server to turn safe_mode off, that may relieve some stress, but as it implies, its no longer in safe_mode then.

                              According to phpinfo(), safe mode is off.

                              -Nij

                                Thanks for everyone's help so far. Here is an update.

                                My web hosting provider does not know why this is happening, though they mentioned something about how it might be because they have PHP running as an Apache module (?!?!). So what I am going to do in the meantime is attempt to use PHP's FTP functionality to achieve the same result.

                                -Nij

                                  I'm happy to report that I'm able to achieve the results I wanted using the PHP FTP connection functions. I can make directories and upload files with reckless abandon. Thanks to everyone who helped me out in this.

                                  -Nij

                                    I'd rather have it running as a module than as a CGI any day.

                                      Write a Reply...