...

View Full Version : mkdir problems....can't figure it out...



tbarbedo
03-16-2009, 05:10 AM
I am just trying to create a simple directory through PHP..


<?php
if(mkdir("path/to/my/dir", 0777)) {
echo "dir created.";
} else {
die("error");
}
?>

I get the following error....


Warning: mkdir() [function.mkdir]: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\makedir.php on line 2
error

Can someone please help me? I cannot figure out why this is happening...

Thanks

milanchheda
03-16-2009, 05:49 AM
The 'mkdir' function doesn't function correctly on Windows when the pathname contain space(s) on the final. PHP returns a warning, and the directory isn't created.

The 'mkdir' function doesn't function correctly on Windows when the path
contains forward slashes. The part of the path with the forward slashes
doesn't get created.

mkdir('c:/a/b/c/d', 0775, true);

You get the error message:
Warning: mkdir() [function.mkdir]: No such file or directory

Please use backslashes under Windows or use the constant DIRECTORY_SEPARATOR.

mkdir('c:\a\b\c\d', 0775, true);
mkdir('c:'.DIRECTORY_SEPARATOR.'a'.
DIRECTORY_SEPARATOR.'b'.
DIRECTORY_SEPARATOR.'c'.
DIRECTORY_SEPARATOR.'d', 0775, true);

kokjj87
03-16-2009, 05:56 AM
You need to create the directory recursively, mkdir function does not understand paths..

Here is how you do it recursively..


<?php
function make_dir($dir, $chmod)
{
if(!is_dir($dir))
{
$temp = explode('/', $dir);
$cur_dir = '';
for($i = 0; $i < count($temp); $i++)
{
$cur_dir .= $temp[$i] . '/';
if(!is_dir($cur_dir))
{
//create the folders
if(@ mkdir($cur_dir, $chmod) && ($cur_dir != getcwd()))
{
echo $cur_dir." Ok.<br/>";
}
}
}
}
}

make_dir('path/to/my/dir', 0777);
?>

tbarbedo
03-16-2009, 03:36 PM
Thanks for the help guys.... Problem was the forward slashes...changed them to \ and it seems to work fine now..

thanks again!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum