简体   繁体   中英

Can I change current directory to parent directory using PHP __DIR__ constant?

I am using PHP magic constant to move uploaded file to a new location, and the upload handler file location is inside " _inc " file inside the main application folder like this:

"path/tasksapp/_inc/upload_handelr.php"

So; when I use __DIR__ I get the path where the upload hander is exist:

"path/tasksapp/_inc/"

While the new location for uploaded file should be:

"path/tasksapp/uploads"

Is there's any option or attribute I can use with __DIR__ constant so I can change current directory to parent directory:

change:

"path/tasksapp/_inc/"

to be:

"path/tasksapp/"

I recommend dirname(__DIR__) :

  • it's portable (works on Windows where a/b/../c is not allowed)
  • it's readable

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