如何通过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:

<?php

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


if(mkdir("/upload/" . $newdir, 0777))
{
echo "Directory has been created successfully...";
}
else
{
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.

/upload/ is almost certainly wrong. It points to the "upload" directory in the root directory, where you most likely don't have the right to create one.

You probably mean upload/.

//new folder  you want to create
$newfolder="145";
//get the current working directory.
$curdir= getcwd();
//append the "upload" folder which already exits in ur working directory alog with the new directory name  "$newfolder"
$dir= $curdir."\uploads"."/$newfolder";
//check if directory exits
if(is_dir($dir))
{
    echo " Directory exists";
}
else
{
    //create new directory recursively
    mkdir($dir,0777,true);
    echo " Directory Created";
}