- /images
- /images/thumbs
- /images/icons
- /css
- /javascripts
- /content
- /content/articles
- /content/tutorials
Anyhow here is what I threw together for him:
CODE
<?php
/* ************************************************************ */
/* */
/* Configuration area */
/* */
/* ************************************************************ */
// The total number of input boxes to show for the addition of foldernames:
$size = 14;
// Default root path
$root = "/home/username/public_html";
// An array of the default folders to be automatically inserted into the form.
$default_folders = array('/images','/images/thumbs','/javascripts','/private','/css','/content');
// File Mode (Permissions) - Ignored by Windows
$mode = "0755";
/* ************* DO NOT EDIT BELOW THIS LINE! ************* */
/* ************* DO NOT EDIT BELOW THIS LINE! ************* */
/* ************* DO NOT EDIT BELOW THIS LINE! ************* */
function build_input_field($type, $name, $value = '', $size = '', $maxlength = '', $option = '', $prepend = '', $append = '') {
// Function written by Marcus L. Griswold (vujsa)
// Can be found at http://www.handyphp.com
// Do not remove this header!
$field = "<input type=\"$type\" name=\"$name\"";
if($value) $field .= " value=\"$value\"";
if($size) $field .= " size=\"$size\"";
if($maxlength) $field .= " maxlength=\"$maxlength\"";
if($option) $field .= " $option";
$field .= ">";
$field = $prepend.$field.$append;
return $field;
}
if(!$_POST){
// Do Input form
$page_title = "Handy PHP Folder Creation System - Start\n";
$body = "\t\t<div style='text-align: center; font-size: 18pt; font-weight: bold; color: navy;'><span>Handy PHP Folder Creation System</span></div><br />\n";
$body .= "\t\t<br />\n";
$body .= "\t\t\t<form action = '' method = 'post'>\n";
$input_field .= build_input_field('input', 'root', $root, 50, 255, 'title = "Insert the exact root path to the new folder you want to create."', "\t\t\t\tRoot Path: ", "<br />\n\t\t\t\t<br />\n");
for($x=1; $x<=$size; $x++){
$name = 'folder' . $x;
$y = $x - 1;
if($default_folders[$y]){
$value = $default_folders[$y];
}
else{
$value = NULL;
}
if($x < 10){
$z = " ";
}
else{
$z = " ";
}
$input_field .= build_input_field('input', $name, $value, 30, 255, 'title = "Insert the relative path of your new folder without a trailing slash."', "\t\t\t\tFolder $x:$z", "<br />\n");
}
$input_field .= build_input_field('submit', 'submit', 'submit', '', '', '', "\t\t\t\t<br />\n\t\t\t\t ", " ");
$input_field .= build_input_field('reset', 'reset', 'reset', '', '', '', " ", "<br />\n");
$body .= $input_field;
$body .= "\t\t\t</form>\n";
}
else{
// Do the folder creation
$page_title = "Handy PHP Folder Creation System - Finished\n";
$body = "\t\t<div style='text-align: center; font-size: 18pt; font-weight: bold; color: navy;'><span>Handy PHP Folder Creation System</span></div><br />\n";
$body .= "\t\t<br />\n";
$root = $_POST['root'];
for($x=1; $x<=$size; $x++){
$folder_name[$x] = $_POST['folder' . $x];
$full_path = $root . $folder_name[$x];
if($folder_name[$x] && !file_exists($full_path)){
if(@mkdir($full_path, $mode)){
$body .= "<b>" . $full_path . "</b><span style='color: #230BFD;'> Was Created!</span><br />\n";
}
else{
$body .= "<b>" . $full_path . "</b><span style='color: #FF1515;'> Was not created: Unknown Error!</span><br />\n";
}
}
else if($folder_name[$x] && file_exists($full_path)){
$body .= "<b>" . $full_path . "</b><span style='color: #FF1515;'> Was not created: Directory Already Exists!</span><br />\n";
}
}
}
?>
<html>
<head>
<title>
<?php echo $page_title; ?>
<\title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="M. L. Griswold / HandyPHP.com">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" style="font-family:verdana; font-size: 10pt;">
<?php echo $body; ?>
<br />
For technical support for this script, please visit <a href="http://www.handyphp.com" title="Handy PHP - A PHP Resource Site">Handy PHP</a>.
<br />
<hr />
<br />
<center style="font-size:8pt;">©2007 <a href="http://www.handyphp.com" title="Handy PHP - A PHP Resource Site">Handy PHP</a></center>
</body>
</html>
There a couple of notes about this script though:
This script offers absolutely no security features. This means that if made publicly available, anyone on the internet could create new directories on your server. You need to protect yourself by placing this script in a private or password protected directory on your server.
If used on a unix/linux machine, the new folders will be owned by the server and not the account owner because the directory was actually created by the server!
You must create the parent before the child! if you want /images/icons, you must either create /images first or is must already exist on the server!
By modifying the configuration section of the script, you can make the scripts default values match your environment which will make the script easier to use.
There is one thing that I request:
Please leave the entire build_input_field function section of the script intact. It offers great flexability if use correctly and shouldn't require any modification for inclusion in any script. It is a function that I personally wrote and made publicly available to everyone to use. For more information about this and other functions I have written, please visit Handy PHP. Basically, if you want to use this function or redistribute it, leave it intact with the credit header. However, if this function inspires you to rewrite or recreate a function that performs the same task, I welcome you to do so.
I'll keep you posted as to the developement of an FTP version of this script via this topic.
vujsa

