Presto Presto - 6 months ago 6x
PHP Question

How Do I Create a Sub-Folder via PHP?

I am trying to create a directory that is inside of a folder called upload. Here is my current simple code that I tried to get this done:


$thisdir = getcwd();
$new_dir = '145';

if(mkdir("/upload/" . $newdir, 0777))
echo "Directory has been created successfully...";
echo "Failed to create directory...";

There must be some simple fix that I am missing. Can you place it? Thanks.


Your php daemon will not have permission, by default, to write inside a folder called /upload (/ being the root directory). You would need to make this folder write accessible for this command to work.

However, saying this, surely this problem is resulting from an error with your code and you aren't working within your current directory. I am guessing your code should read...

if(mkdir($thisdir . "/upload/" . $newdir, 0777))

In which case it should work fine.