开发者

PHP - Is there a decent way so that the calling of mkdir creates folders relative to the web root?

The directory and file structure is as follows:

C:\xampp\htdocs\PHP_Upload_Image_MKDIR\uploaded
C:\xampp\htdocs\testA.php // as开发者_运维问答 follows

$userID = 's002';
$uploadFolder = '/PHP_Upload_Image_MKDIR/uploaded/';
$userDir = $uploadFolder . $userID;
mkdir($userDir, 0700);

If I call testA.php, then the following folder will be created.

C:\PHP_Upload_Image_MKDIR\uploaded\s002

However, the desired result should be the following:

C:\xampp\htdocs\PHP_Upload_Image_MKDIR\uploaded\s002

I would like to know a decent method so that the mkdir creates folder relative to the root of the web

C:\xampp\htdocs\
or
C:\wamp\www

Then in the future, I don't have problems to move this application to a web hosting site.

Thank you


You can:

  • Create a file with defines that's always included and where you define what's the server root (or whatever prefix) so that you prepend it to the directory.
  • Use a relative directory to the script. The directory of the script can be obtained with dirname(__FILE__).
  • Use a relative path to the current directory. The current directory, if not changed, is usually the directory of the PHP script that was originally called (usually not a good option).
  • Use $_SERVER[DOCUMENT_ROOT] (not a very good option, you might want your application in a subdirectory, and whether this value is available depends on the web server).


$uploadFolder = $_SERVER['DOCUMENT_ROOT'] . '/PHP_Upload_Image_MKDIR/uploaded/';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜