Create folder in php

Asked

Viewed 12,115 times

2

I have to create a folder on the online server.

The file that creates folder is on site.com.br/example/.php file

I need to create the folder at the root of the site, example: site.com.br/files/name_folder

But every time you say that there is no directory informed. I think it is because I am not putting the correct URL. I know that if you do mkdir(site.com.br) it doesn’t work... how to proceed?

I’m using the remote mkdir("/public_html/filemanagerarquiv", 0777);

the site is within public_html.

  • 2

    Put the code you’re using!

  • Edited friend!!

  • Put the PHP code you are using, there is some variable that takes the base URL of the project?

  • Take a look at that answer, it might help. http://answall.com/questions/124407/como-crea-uma-pasta-para-cada-usu%C3%a1rio-em-php

2 answers

9


You can try this example:

<?php

mkdir(__DIR__.'/arquivos/nome_da_pasta/', 0777, true);

?>

or

mkdir(dirname(__FILE__).'/arquivos/nome_da_pasta/', 0777, true);

Note that the 777 permission allows full access to the folder, which is not prudent in certain situations.

Check the necessary permissions here.

  • Opa worked well...and how do I create the folder in a directory above? how do I "../../" ?

  • Opa legal, do not forget to validate the answer...

2

To create in a directory above, simply replace the "DIR" by "." for example:

mkdir('../arquivos/nome_da_pasta/', 0777, true);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.