astralaaron Posted December 4, 2007 Share Posted December 4, 2007 can someone tell me how to create a new folder on my website by entering the folder name in a text field and submitting it.and also how to delete the folder, thanks.**edit**: I just found this<?phpmkdir("/path/to/my/dir", 0700);?>at php.netanyone know what the 0700 means? Link to comment Share on other sites More sharing options...
Synook Posted December 4, 2007 Share Posted December 4, 2007 To create a folder, you can use the PHP mkdir() function, for which you can access the $_REQUEST array to find out what value was entered into the text input. To remove an (empty) directory, you can use rmdir() (like DOS ). A complete script could be something like <?phpif (isset($_POST['mkdir'])) {mkdir($_POST['mkdir']) ? echo "Directory \"{$_POST['mkdir']}\" created sucessfully!" : echo "Error creating directory \"{$_POST['mkdir']}\"";echo "<br /><br />";}if (isset($_POST['rmdir'])) {rmdir($_POST['rmdir']) ? echo "Directory \"{$_POST['rmdir']}\" removed sucessfully!" : echo "Error removing directory \"{$_POST['rmdir']}\"";}?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><input type="text" name="mkdir" /> <input type="submit" value="Make Directory" /></form><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><select name="rmdir"><?php$folders = glob("*", GLOB_ONLYDIR);foreach ($folders as $folder) echo "<option>$folder</option>";?></select> <input type="submit" value="Remove Directory" /></form> anyone know what the 0700 means?That is the permissions (who can do what to a file) - have a look at http://www.w3schools.com/php/func_filesystem_chmod.asp Link to comment Share on other sites More sharing options...
astralaaron Posted December 4, 2007 Author Share Posted December 4, 2007 thanks, what does this part do?<?php$folders = glob("*", GLOB_ONLYDIR);foreach ($folders as $folder) echo "<option>$folder</option>";?> Link to comment Share on other sites More sharing options...
Synook Posted December 4, 2007 Share Posted December 4, 2007 That creates a dropdown menu of all current folders in the script's directory (to aid removing them). Link to comment Share on other sites More sharing options...
astralaaron Posted December 4, 2007 Author Share Posted December 4, 2007 i tried posting your code into a new file and it had errors Link to comment Share on other sites More sharing options...
Synook Posted December 4, 2007 Share Posted December 4, 2007 Err... what error? Link to comment Share on other sites More sharing options...
Synook Posted December 4, 2007 Share Posted December 4, 2007 Updated code: <html><body><?phpif (isset($_POST['mkdir'])) {echo (mkdir($_POST['mkdir']) ? "Directory \"{$_POST['mkdir']}\" created sucessfully!" : "Error creating directory \"{$_POST['mkdir']}\"");echo "<br /><br />";}if (isset($_POST['rmdir'])) {echo (rmdir($_POST['rmdir']) ? "Directory \"{$_POST['rmdir']}\" removed sucessfully!" : "Error removing directory \"{$_POST['rmdir']}\"");}?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><input type="text" name="mkdir" /> <input type="submit" value="Make Directory" /></form><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><select name="rmdir"><?php$folders = glob("*", GLOB_ONLYDIR);foreach ($folders as $folder) echo "<option>$folder</option>";?></select> <input type="submit" value="Remove Directory" /></form></body></html> Will work Link to comment Share on other sites More sharing options...
astralaaron Posted December 4, 2007 Author Share Posted December 4, 2007 cool, that works.do you know a way to have a form upload multiple pictures at the same time?**thanks alot by the way Link to comment Share on other sites More sharing options...
Synook Posted December 4, 2007 Share Posted December 4, 2007 do you know a way to have a form upload multiple pictures at the same time?Well, you can have multiple inputs of type file as then use foreach or something to loop through and move them one by one. Just remember to give them all different names.<input type="file" name="file1" /><input type="file" name="file2" /><input type="file" name="file3" /><!-- Etc... --> Link to comment Share on other sites More sharing options...
astralaaron Posted December 4, 2007 Author Share Posted December 4, 2007 Well, you can have multiple inputs of type file as then use foreach or something to loop through and move them one by one. Just remember to give them all different names.<input type="file" name="file1" /><input type="file" name="file2" /><input type="file" name="file3" /><!-- Etc... --> thanks alot, will try it out later Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.