Deoctor Posted February 26, 2010 Share Posted February 26, 2010 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"; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 Define 'it is not working..' Also, what exactly is the point of executing chdir ? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 26, 2010 Author Share Posted February 26, 2010 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.. Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 You do realize mkdir has a recursive option? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 26, 2010 Author Share Posted February 26, 2010 You do realize mkdir has a recursive option? no i dont knw that .. can u teach me that.. Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 mkdir('foo/bar/bob', 0777, true); Will create all those directories in one go. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 26, 2010 Author Share Posted February 26, 2010 10q for that.. ill try with this one Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 What the heck is 10q ? English please. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 26, 2010 Author Share Posted February 26, 2010 What the heck is 10q ? English please. <?php $10q="Thank You"; $10q .=""; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in #msg1371076 on line 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.