JS1986
JS1986

Reputation: 1950

mkdir problem PHP

Warning: mkdir() [function.mkdir]: No such file or directory in

I keep getting this annoying message when trying to create new directories. my function is

mkdir("../".$a."/".$b);

$a = an existing filepath
$b = new folder i wish to create

function is executed from another directory: my structure looks like this:

/htroot/site/c/ <- where im executing the function
/htroot/site/a/b <- where i wish to create the directories.

if i execute the following, it creates the desired effect but in the same directory as the function.

mkdir($a."/".$b);

HI ALL THANKS FOR THE HOT RESPONSES

C:\wamp\www\book\admin\import //is my __DIR__ for that script
C:\wamp\www\book\admin\property // already exists

C:\wamp\www\book\admin\property\name // want i want end result

Upvotes: 0

Views: 5308

Answers (2)

Phil
Phil

Reputation: 164731

Depending on how your function is included, the PWD could be anywhere. You're best to use an absolute path.

You can also grab the current script's directory using __DIR__ (v5.3+) or dirname(__FILE__)

For example

// use realpath to resolve any symbolic links
$newDir = realpath(__DIR__ . '/../' . $a) . '/' . $b;
mkdir($newDir);

See realpath()

Upvotes: 4

hobbs
hobbs

Reputation: 239652

Whatever "../$a" is, there's no such directory, however much you want there to be. Maybe there's a symlink, and .. isn't the directory you think it is.

Upvotes: 2

Related Questions