user883594
user883594

Reputation: 5

how to create a directory in php

I am trying to create a directory on my server. Here is my code for one directory...

$path = "UserIds/";
$di = $path . $userid;

mkdir($di,0777);

It's work fine but here I need another directory. Here is my code...

$dir="$di./".date("Y/m/d");

mkdir($dir,0777); 

This does not make the directory. What is wrong?

Upvotes: 0

Views: 153

Answers (2)

Bjoern
Bjoern

Reputation: 16304

Use the quotation marks differently:

 $dir= $di . "/" . date("Y/m/d");

If you use PHP version > 5.0.0, maybe add a third parameter in your mkdir command: recursive (as pointed out in the php manual):

 mkdir($dir, 0777, TRUE); 

Upvotes: 2

alex
alex

Reputation: 490233

You need to make it recursive by setting the third argument to TRUE.

mkdir($dir, 0777, TRUE);

Upvotes: 1

Related Questions