Skip to main content
Known Participant
June 1, 2011
Question

folder accessing via ftp

  • June 1, 2011
  • 1 reply
  • 422 views

i am trying to access a folder that is created on the server.  here is my code that I use to create it:

<?php

   
    if (isset($_POST['submit'])) {
       
        $name = $_POST['gname'];
        $description = $_POST['gdescription'];
       
        mkdir("$name",'0777');
       
       
    }

?>

here is the error i get when i try to access the folder on the server:

This topic has been closed for replies.

1 reply

Community Expert
June 1, 2011

Given that your code is PHP I'll assume a Unix server.  I don't see this as much anymore, but if your host is not running suPHP then scripts creating through web programming will be created with the ownership of user "nobody" in which case since you are not "nobody" you do not have ownership rights to modify the folder.  I can't say 100% that this is the case, but it is a strong possibility.  If you have a decent FTP client you might be able to read the ownership properties (or via web-based administration).  It is possible that your host might need to get involved if you do not have ownership of the folder.

Known Participant
June 1, 2011

i guess there is a difference b/w a directory and a folder.... you cannot access a directory.  so i guess i have to create a folder.  i would like a folder created when a user signs up on my site.

David_Powers
Inspiring
June 1, 2011

future-architect wrote:

i guess there is a difference b/w a directory and a folder....

You guess wrong. The correct computer terminology is directory. Windows and Mac both thought that sounded too intimidating for non-technical people, so they used the term "folder" instead. Folders and directories are the same.

Looking at your original code, I notice a couple of things:

if (isset($_POST['submit'])) {
    $name = $_POST['gname'];
    $description = $_POST['gdescription'];
    mkdir("$name",'0777');
}

First of all, you're not making any checks on the value of $_POST['gname']. It could contain illegal characters or be trying to probe your file system.

Secondly, you're not checking whether there's already a directory of the same name.

Thirdly, you don't need quotes around $name in the first argument to mkdir(). The variable on its own is enough. Even more important, there should not be any quotes around 0777. It's an octal number, not a string. In fact, you don't need the second argument, because 0777 is the default value.

Finally, what operating system is your server running on? The second argument to mkdir() has no effect on a Windows server.