我有这个:
move_uploaded_file($File['tmp_name']['File'], $FilePath);
哪里
$FilePath is '/data/www/MIMICm/Common/Upload/PPKInside/CustomImage/6/52'
其中'PPKInside'是指向'../../MIMI/Common/Data/'的符号链接(symbolic link),其中'Data'是指向'/mnt/nfsnew/DIDIData/PPKInside/Data'的符号链接(symbolic link)
到目前为止,我发现 '/mnt/nfsnew/' 为空,'/DIDIData/PPKInside/Data' 缺少目录...
检查目录是否存在并在不存在时创建它们的最佳方法是什么?因为目前
is_dir('/data/www/MIMICm/Common/Upload/PPKInside');
返回 false,我需要使用 is_link() 但在第一个链接('PPKInside')之后我无法检查其子目录是否存在并在需要时创建它们...
最佳答案
realpath将展开给定路径中的任何符号链接(symbolic link)并告诉您最终的绝对文件(目录)是否存在:
realpath() returns FALSE on failure, e.g. if the file does not exist.
如果不存在,您可以使用mkdir一次性创建完整的目录路径,并一路添加缺少的子目录。设置了 $recursive
标志。
$FilePath = '/data/www/MIMICm/Common/Upload/PPKInside/CustomImage/6/52';
if (!realpath($FilePath)) {
mkdir($FilePath, 0777, true);
}
请注意,此特定示例为每个人创建具有读/写/执行权限的任何目录。您可能需要更改 0777 以更好地适合您的特定设置。
关于php - 如何在 php 中检查带有符号链接(symbolic link)的目录是否存在以及是否不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29209306/