Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Automated File Structure Creation Script, As Requested By Mark420
vujsa
post Jan 10 2007, 02:39 AM
Post #1


Absolute Newbie
Group Icon

Group: Admin
Posts: 887
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



While chatting with Mark420 today on the shoutbox, he mentioned that he was looking for a script to create his entire folder structure with just a click of a button. For example, he wanted the following folders created in his root folder by just clicking submit.
  • /images
  • /images/thumbs
  • /images/icons
  • /css
  • /javascripts
  • /content
  • /content/articles
  • /content/tutorials
Presumably this would be used for some type of installation system or other quick server setup situation.

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
Go to the top of the page
 
+Quote Post
mastercomputers
post Jan 11 2007, 02:15 AM
Post #2


BUG.SWAT.PATROL
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



I should probably start contributing to HandyPHP though, but how to put it, it's not the most pleasant looking site, it needs work.

Your function build_input_field could be improved.

Firstly, you should use HTML's defaults for the input element, this is just like doing <input /> what would you expect it to be if displayed in your browser?

You should then make sure you know all the attributes for the types of input and what attributes it can accept (this is where you create validations for the type of data it can accept), that way you can make sure you limit the attributes of the input to only using what it can based on the type specified, must ensure no exploitation too.

If I said the type is password, I can't use the attribute checked="checked" because it's the wrong type. Also I see that you force some attributes, that aren't really required, nor do you properly check their value existence, you would have to turn on error_reporting(E_ALL); to see what I mean.

I'm sure there's more that can be done, maybe more along the lines as to creating a complete HTML DOM API or specific areas like forms, tables, lists, etc


Now for the whole script, to me it's not flexible enough to be used widely, you need to give the user more control, allow them to make changes without altering the file itself, you will need to put in security for it too.

I notice some things in your notes above too, these things you could solve through your script, those would be beneficial to have.

I might take the opportunity to work on this script when I find time to.

Cheers,

MC
Go to the top of the page
 
+Quote Post
Mark420
post Jan 15 2007, 10:49 AM
Post #3


The Modernator
Group Icon

Group: Members
Posts: 486
Joined: 6-August 06
From: The Interweb!
Member No.: 15,021



Hey Vujsa...I finally got time over the weekend to mess around with the script..been too busy this week with work and with kids;(((

But its great..I changed a few of the folder names but apart from that it worked fine..cheers!!!!!

Marky;)
Go to the top of the page
 
+Quote Post
vujsa
post Jan 17 2007, 04:29 AM
Post #4


Absolute Newbie
Group Icon

Group: Admin
Posts: 887
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714



Mark420, glad to hear that the script is working exactly the way it was indended.

I developed an FTP version that does the same process but offers the security benefits of requiring the FTP login information each submission. Also, the FTP version will ensure that the directories you create have the proper ownership.

Let me know if you are interested in it and I'll pass it along.

vujsa
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Make A Text Based Online Game Script ?(23)
  2. PHP: Writing A Generic Login And Register Script(14)
  3. Shut Down, Restart, Log Off XP Using A Batch File(23)
  4. How To Save A Image In Pdf File And Download It?(10)
  5. Recover Tables From A MySQL .frm File(8)
  6. Bash Script To Display Your Ip(9)
  7. Help Needed To Create Login Script With Perl/cgi(21)
  8. Need Help With A PHP - MySQL Registration Script(13)
  9. Finding Yahoo Account Creation Date(1)
  10. Uploading Image File Through JSP Code To Server(9)
  11. How To Use Psd File(14)
  12. PHP Tutorial: Form Verification And Simple Validation(12)
  13. Running Vba Script In Excel(6)
  14. Deleting A Corrupt File(25)
  15. Need Help Urgently (missing Or Corrupt Hal.dll File).(6)
  1. Very Simple Login-script(18)
  2. A Simple Register Script(3)
  3. Auto-click Script(7)
  4. Is A Php File Searchable?(8)
  5. Safari And Hosts File(8)
  6. Myspace Gold Script(2)
  7. Looking For Script(5)
  8. How To Copy File & Folders From Linux To Windows?.(12)
  9. Need To Edit A Wav File [solved](1)
  10. Engine001 Game Creation Software(2)
  11. Mysql And User File_priv(0)
  12. Creating A Php Login Script(3)
  13. Myspacetv Download Php Script Help(6)


 



- Lo-Fi Version Time is now: 30th August 2008 - 04:34 AM