Jump to content

createing a folder


astralaaron

Recommended Posts

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

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

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

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

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

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

Archived

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

×
×
  • Create New...