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"; ?> Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/ 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 ? Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018414 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.. Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018422 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? Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018430 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.. Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018436 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. Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018450 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 Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018455 Share on other sites More sharing options...
trq Posted February 26, 2010 Share Posted February 26, 2010 What the heck is 10q ? English please. Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018469 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 .=""; ?> Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018485 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 Link to comment https://forums.phpfreaks.com/topic/193441-create-a-subfolder/#findComment-1018698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.