Hot to create a folder using PHP in a subdirectory?

I am trying to use PHP command to create a folder in the same folder as the command-file is run.
This worked when the PHP command script was located in public_html aka top level directory.

However when locating this working code into a sub-directory, it is giving an error on this part of the code: 0777
This number is a file permission. Does mean it doesn’t have permission to write to sub-folders?

Warning: mkdir(): No such file or directory in /storage/h10/365/1360365/public_html/LR/CreateSubfolder.php on line 11
Failed to create directory…

Actual code that runs, but only in the top level directory:

<<?php

$thisdir = getcwd();
$new_dir = ‘145’;

if(
mkdir(
$thisdir .
“LR/upload/” .
$new_dir,
0777))
// creates a subfolder called “upload” and a new file called “145”
{
echo “Directory has been created successfully…”;
}
else
{
echo “Failed to create directory…”;
}
?>

So I was reading here: http://stackoverflow.com/questions/6043205/make-folder-and-subfolder-in-that-folder

And I added “, true” right affter the 0777, inside the mkdir() parenthesis. and the command runs now.

Problem Solved.

1 Like