Seems that there exists a file with the same name as the directory. That's why is_dir()
returns false
but mkdir()
fails because the file exists.
You can change this to:
if (!file_exists($this->folder)) mkdir($this->folder);
This should work so far.
However it is necessary to mention that such file existence tests are vulnerable against race conditions by design. That's why you need to additionally check the return value of mkdir()
:
if (!file_exists($this->folder)) {
if(@mkdir($this->folder) === FALSE) {
throw new Exception('failed to create ' . $this->folder);
}
}
This may not being required if you (or the framework) has registered a global error handler which turns warning into exceptions, because mkdir()
will throw a warning on errors.