简体   繁体   中英

PHP MKDIR inside server root but outside domain root folder?

I have a domain root which is a folder within the server root. How can I mkdir inside a different folder within the domain root?

ROOT > DOMAIN ROOT FOLDER > PHP MKDIR

ROOT > IMAGE FOLDER > MKDIR HERE

I need the php in the 'domain root folder' to create a directory within the 'image folder'. Any help?

You can usually do something like this:

mkdir('../images/newfolder');

You may have to add more ../../ on to the front of this, depending on where you are running the script from exactly. Each ../ moves you up another level, so it seems like just one would work here given your example, but you have to be sure you are where you think you are.

You could also use absolute path in your php-script.

mkdir('/root/images/new_folder');

Make sure that your web-server has permissions for writing to specific folder.

I usally work from the directory my current script is located in and maneuver my way to the desired location from there. Works fine as long as you don't move you script. In addition, it will be easier to keep track of where everything is relative to the script.

You can get the current path with:

$path = dirname(__FILE__);

Then appending ../ to go deeper etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM