Jump to content

problem with the "mkdir()" function.


atar.yosef

Recommended Posts

Hi there! I'm very new in PHP and just doing my first steps in this great world. I have copy&paste a code snippet from php.net which demonstrate how to use the mkdir() function.the code snippet was very short:

<? mkdir("/path/to/my/dir", 0700);?>

I have saved this file into my ftp server with the php extension and then I load this page into my browser.the code didn't work as I expected and didn't create a directory in my server.can someone explain me please what's wrong with this code? Thanks in advance!! atar.

Link to comment
Share on other sites

No error messages? All I can do is make guesses with the information you have provided. mkdir() won't work if you try to create multiple nested directories all at ones. You need to create them one by one.

  • Like 1
Link to comment
Share on other sites

@ingolme:Thanks for replying.No error messages. Also, this example was taken directly from the php.net site themselves. So it's expected to work even when creating multiple nested directories at once. However, I have also tested this example with only one directory at the directory path and it also didn't work. Maybe I need to use at some wrappers such the "ftp://" wrapper?Thanks in advance!!Atar.

Link to comment
Share on other sites

If there aren't any error messages and the directory isn't being created then it probably means that PHP's error messages aren't being displayed. Put this at the beginning of your page:

ini_set('display_errors', 1);error_reporting(E_ALL);

The code in the PHP manual works only when put in the right context.

Link to comment
Share on other sites

@ingolme: Thanks for replying!! later yesterday I have noticed that the code indeed worked and it created a folder on my server. probably there was some delay in the server because it didn't show me this new directory after I reloaded the page but only several minutes thereafter. I am just wondered what do we need to do in a case we want to create several directories at once, is there any solution? thank you!! atar.

Link to comment
Share on other sites

Pass a true value for the third parameter to create a recursive structure. Look at the examples in the manual.

Also, this example was taken directly from the php.net site themselves. So it's expected to work even when creating multiple nested directories at once.
Don't think like that. There are plenty of requirements for different parts of PHP, the examples on php.net are not all expected to work on every server regardless of the settings or other things the server supports. The examples are supposed to work in specific situations. You need to read the manual and the notes to see how the functions work, it's not enough to just copy and paste examples and expect everything to immediately work. Those examples will also not work if you don't have write permission, for example.
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...