0

I have already define my selected folder name to create in my mkdir method. But error saying that "mkdir(): No such file or directory". The directory is correct if I removed away the "/"."Folder"."/".

Updated Working code:
$Name = "John";
if(!is_dir("document/".$Name))
{
$dir = "documents/".$Name."/";
    mkdir($dir,0777,true);
    $dir2 = $dir."Folder/";
    mkdir($dir2);
    move_uploaded_file($_FILES["file"]["tmp_name"],$dir2."/".$_FILES["file"]["name"]);

}

Thanks to xdazz!

5
  • Why "/"."Folder"." ? Shouldn't that be "/Folder/" ? Commented Jul 7, 2012 at 13:10
  • want to create a inner folder to store that particular document. Even i change it to "/Folder/". It still gives me the same error Commented Jul 7, 2012 at 13:10
  • Are you sure that 'documents/'.$Name; exists? mkdir won't create missing folders in path. Commented Jul 7, 2012 at 13:12
  • Yes, it exists. I can successfully created 'documents/'.$Name; But not "documents/".$Name."/"."Folder"."/"; Commented Jul 7, 2012 at 13:12
  • 1
    @user976050 The way you use mkdir won't create missing folders. For example, mkdir('document/'.$name); will create folder with the name that will be value of $name. but mkdir('document/'.$name.'/folder'); won't create first folder $name and then "folder" inside if the folder named by $name is missing. Commented Jul 7, 2012 at 13:16

1 Answer 1

1

Try mkdir($dir,0777, true);, "document/".$Name is not a dir yet, so you need to make dir recursive .

Sign up to request clarification or add additional context in comments.

2 Comments

@user976050 The third parameter of mkdir let you make dir recursive, did you try it?
Anyway is there any other way I can automatic create the folder behind the "document/".$Name."/". Means create document/Name/Folder, document/Name/Folder1..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.