+my $curdir = $cgi->param('curdir') || '';
+my $newfile = $cgi->param('newfile') || '';
+
+# Create physical and virtual path for the new file
+# This section has to be optimized - ugh!
+
+my $new_physical = '';
+my $new_virtual = '';
+
+if($newfile ne '')
+{
+ $curdir = upper_path($file) if($curdir eq '');
+ my $path = clean_path($curdir.$newfile);
+
+ # Extract file and directory name...
+
+ my $file = file_name($path);
+ my $dir = upper_path($path);
+
+ # ... check if the directory exists ...
+
+ unless(-d clean_path($config{'fileroot'}."/".$dir))
+ {
+ abort("The directory where you want to create this file or directory doesn't exist.");
+ }
+
+ # ... and check if the path is above the root directory
+
+ unless(($new_physical,$new_virtual) = check_path($config{'fileroot'},$dir))
+ {
+ abort("You aren't allowed to create files and directories above the virtual root directory.");
+ }
+
+ # Create the physical and the virtual path
+
+ $new_physical = File::Spec->canonpath($new_physical."/".$file);
+ $new_virtual .= $file;
+}