如何在php中检查是否存在带有符号链接的目录以及是否不创建该目录


How to check in php if directory with symlinks exists and if its not to make it

我有这个:

move_uploaded_file($File['tmp_name']['File'], $FilePath);

何处

$FilePath is '/data/www/MIMICm/Common/Upload/PPKInside/CustomImage/6/52'

其中'PKInside'是指向'../..的符号链接/MIMI/Common/Data/'其中'Data'符号指向'/mnt/nfsnew/DIDIData/PPKInside/Data'
到目前为止,我发现'/mnt/nfsnew/'为空,而'/DIDIData/PPKInside/Data'strong>检查目录是否存在以及创建目录的最佳方法是什么因为目前

is_dir('/data/www/MIMICm/Common/Upload/PPKInside');

返回false,我需要使用is_link(),但在第一个链接('PKInside')之后,我无法检查其子目录是否存在,并在需要时创建它们。。。

realpath将展开给定路径中的任何符号链接,并告诉您是否存在最终的绝对文件(目录):

realpath()在失败时返回FALSE,例如,如果文件不存在。

如果它不存在,您可以通过使用设置了$recursive标志的mkdir,一次创建完整的目录路径,同时添加丢失的子目录。

$FilePath = '/data/www/MIMICm/Common/Upload/PPKInside/CustomImage/6/52';
if (!realpath($FilePath)) {
    mkdir($FilePath, 0777, true);
}

请注意,这个特定的示例为everyone创建具有读/写/执行权限的任何目录。您可能需要更改0777以更好地适应您的特定设置。