我正在嘗試在網絡服務器上創建一個嵌套目錄。代碼創建目錄 $userID"."_blog_images ok,但不是 post_"."$postID"."_images 目錄。我正在使用 Mac。提前致謝。<?php//Create user root image directory if it does not exist if (!is_dir("$userID"."_blog_images")){ mkdir("$userID"."_blog_images"); }//Create post image directory if it does not exist if (is_dir("$userID"."_blog_images")){ if (!is_dir("$userID"."_blog_images/post_"."$postID"."_images")){ mkdir("$userID"."_blog_images/post_"."$postID"."_images", 0777, true); } }?>
1 回答

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
根據評論部分中提供的信息,您希望在sub-dir父母dir已經存在時在其中創建一個
所以你的代碼必須是
<?php
//Create user root image directory if it does not exist
if (!is_dir($userID."_blog_images/")){
mkdir($userID."_blog_images");
}
//Create post image directory if it does not exist
if (is_dir($userID."_blog_images/")){
mkdir($userID."_blog_images/post_".$postID."_images", 0777, true);
}
?>
- 1 回答
- 0 關注
- 154 瀏覽
添加回答
舉報
0/150
提交
取消