how to use mkdir in php

Started on the old forum in June 2012 · view the original in the archive · old links redirect here

7 replies · 881 views · started 14 years ago · 1 min read

4 participants
mansi Developer · 60 posts #1

i m trying to check and make muliple dir in a single command by mkdir command bt nt get success, is there any alternative or how to use it. . Ex- file/a/b/c i want to if there a,b or c dir present if nt create which is nt present. If a, present bt b,c nt then create b and c both.. Pls share if u knw the solution .. At present i m using loop to do this .

mansi Developer · 60 posts #3

i m already using while loop in my script bt i want to do it without loop.. I google this bt not find appriate solution 4 php script.

arnage Lead · 811 posts #4

It goes anyway, both are needed. 🙂

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
arbind004 Junior · 13 posts #5
<?php
$path="download/";
$dirname="muzic";
$final="$path$dirname";
if (!mkdir($final, 0777, true)) {
    die('Failed to create folders...');
}
else
{
mkdir("$final", 0777, true);
chmod("$final", 0777);
echo"Folder Created Successfully!!";
}
?>
shushant Developer · 207 posts #6

Simpler one

   function makedir ($pathname ){
      if(mkdir ($pathname,0700,true)){
      return true ;
      }else{
      return false;
      }
   }

pass multiple path 😀 it will create for u 😀

mansi Developer · 60 posts #7

arbind and sushant thanks 4 ur reply i will try these codes, hope it works, bt my main point is to make to 2 or 3 directory at once.. Like /dir1/dir2/dir3 in a single command i used mkdir -p also got error.

arbind004 Junior · 13 posts #8

try this

<?php
// Desired folder structure
$structure = './depth1/depth2/depth3/';

// To create the nested structure, the $recursive parameter 
// to mkdir() must be specified.

if (!mkdir($structure, 0, true)) {
    die('Failed to create folders...');
}

// ...
?>

Added after 6 minutes:

Try this 101% working

<?php
$foldername="hello";
mkdir("$foldername", 0777);  // create folder 

chmod( "$foldername", 0777 ); // chmod folder to 0777

mkdir("$foldername/pics", 0777); // create folder 

chmod("$foldername/pics", 0777 ); // chmod folder to 0777

echo"Sucessfully created";

?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close