LoginSignup
1
0

More than 3 years have passed since last update.

🐘【PHP】mkdirでディレクトリ作成に失敗したのは再帰的に作成してないから

Posted at

やりたいこと

mkdirでディレクトリを新規作成したいのにできない
その上にあるディレクトリ(/test/)のパーミッションも問題なし

hoge.php
        // /test/は作成済み

        // これは作成できる
        $saveDir = /test/hoge/;
        // なぜか作成できない!?
        $saveDir = /test/hoge/fuga;

        // 存在確認しディレクトリ作成
        if (!file_exists($saveDir)) {
            if (mkdir($saveDir, 0777)) {
                chmod($saveDir, 0777);
            }
        }

やったこと

第三引数がtrueでディレクトリ再帰的作成であった
単純すぎることにつまってた...

hoge.php
        mkdir($saveDir, 0777, true)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0