Jump to content

Create a subfolder


Deoctor

Recommended Posts

Hai

i am trying to create one folder something like this

the root directory will be d:\share

 

so i will ask the user to enter a name of the folder. for example if he gives the name chaitu

 

then it should check the for this folder name if not exists create that. and then create one more folder inside that with the present date.

 

so the folder structure should be like this

d:\share\chaitu\26-02-2010

 

i am trying with this code, but it is not working..

anh help would be appreciated..

<html>
<head>
<title>
Check for files
</title>
</head>
<body>
<tr>
    <td>Folder Name:</td>
    <td><input name="filegive" type="text" id="filegive" size="50" value=""/></td>
    <td><input type="submit" name="Submit" value="ccc" accesskey="ENTER" tabindex="2" /></td>
  </tr>
</body>
</html>
<?php
echo "hai";
$give=$_POST['filegive'];
$path="D:\\share\\";
$path .= "$give\\";
if(!chdir($path))
{
    _directory_exists($path);
}
$date_today=date("d-m-Y");
$path .="$date_today\\";
if(!chdir($path))
{
    _directory_exists($path);
}
//echo getcwd() . "\n";

function _directory_exists($dir)
{
   if(is_dir($dir))
   {
       echo "Directory already there!!!<br>";
   }
   else
   {
       echo "Directory not exists!!!!<br>";
    mkdir($dir);
   }
}

echo getcwd() . "\n";

?>

 

Link to comment
https://forums.phpfreaks.com/topic/193441-create-a-subfolder/
Share on other sites

Define 'it is not working..'

 

Also, what exactly is the point of executing chdir ?

10q for your time thrope..

i have figured out where i was doing wrong..!! ;)

 

<?php
function _directory_exists($dir)
{
   if(is_dir($dir))
   {
       echo "Directory already there!!!<br>";
     chdir($dir);
   }
   else
   {
       echo "Directory not exists!!!!<br>";
    mkdir($dir);
    chdir($dir);
   }
}
function echo_win_drives() 
{

  for($c='A'; $c<='Z'; $c++) 
    if(is_dir($c . ':'))
      echo $c . ': '; 
}

?>
<html>
<head>
<title>
Check for files
</title>
</head>
<body>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST"> 
<table width="500" border="0" cellspacing="4" cellpadding="4" align="center">

<tr>
    <td>Folder Name:</td>
    <td><input name="filegive" type="text" id="filegive" size="50" value=""/></td> </tr> <tr>
    <td><input type="submit" name="Submit" value="ccc" accesskey="ENTER" tabindex="2" /></td>
  </tr>
  </table>
</form>
</body>
</html>
<?php
if(isset($_POST['Submit']))
{
    

echo "hai";
$give=$_POST['filegive'];
$path="D:\\share\\";
$path .= "$give\\";
if(!chdir($path))
{
    _directory_exists($path);
}
$date_today=date("d-m-Y");
$path .="$date_today\\";
if(!chdir($path))
{
    _directory_exists($path);
}
//echo getcwd() . "\n";

//echo_win_drives();
echo getcwd() . "\n";
}
?>

 

now this code is working the way i wanted..

change directory is for checking whether that directory exists or not, if not exists create that directory..

Link to comment
https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018422
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.