+ $new_virtual = encode_html($new_virtual);
+
+ if($new_physical)
+ {
+ return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical);
+
+ mkdir($new_physical,0777) or return error($config->{'errors'}->{'mkdir_failed'},$dir,{DIR => $new_virtual});
+ return devedit_reload({command => 'show', file => $dir});
+ }
+ else
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'templates'}->{'mkdir'});
+
+ $tpl->fillin('DIR','/');
+ $tpl->fillin('SCRIPT',$script);
+
+ my $output = header(-type => 'text/html');
+ $output .= $tpl->get_template;
+
+ return \$output;
+ }
+}
+
+# exec_upload()
+#
+# Process a file upload
+#
+# Params: 1. Reference to user input hash
+# 2. Reference to config hash
+#
+# Return: Output of the command (Scalar Reference)
+
+sub exec_upload($$)
+{
+ my ($data,$config) = @_;
+ my $physical = $data->{'physical'};
+ my $virtual = $data->{'virtual'};
+ my $cgi = $data->{'cgi'};
+
+ return error($config->{'errors'}->{'no_directory'},upper_path($virtual),{FILE => encode_html($virtual)}) unless(-d $physical && not -l $physical);
+ return error($config->{'errors'}->{'dir_no_create'},$virtual,{DIR => encode_html($virtual)}) unless(-w $physical);
+
+ if(my $uploaded_file = $cgi->param('uploaded_file'))
+ {
+ if($cgi->param('remote_file'))
+ {
+ $uploaded_file = $cgi->param('remote_file');
+
+ $uploaded_file =~ s!/!!g;
+ $uploaded_file =~ s!\\!!g;
+ }
+
+ # Process file upload
+
+ my $filename = file_name($uploaded_file);
+ my $file_phys = $physical.'/'.$filename;
+ my $file_virt = encode_html($virtual.$filename);
+
+ if(-e $file_phys)
+ {
+ return error($config->{'errors'}->{'link_replace'},$virtual) if(-l $file_phys);
+ return error($config->{'errors'}->{'dir_replace'},$virtual) if(-d $file_phys);
+ return error($config->{'errors'}->{'exist_no_write'},$virtual,{FILE => $file_virt}) unless(-w $file_phys);
+ return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) unless($cgi->param('overwrite'));
+ }
+
+ my $ascii = $cgi->param('ascii');
+ my $handle = $cgi->upload('uploaded_file');
+
+ return error($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
+
+ # Read transferred file and write it to disk
+
+ read($handle, my $data, -s $handle);
+ $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
+ file_save($file_phys,\$data,not $ascii) or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt});
+
+ return devedit_reload({command => 'show', file => $virtual});
+ }
+ else
+ {
+ my $tpl = new Template;
+ $tpl->read_file($config->{'templates'}->{'upload'});
+
+ $tpl->fillin('DIR',encode_html($virtual));
+ $tpl->fillin('DIR_URL',escape($virtual));
+ $tpl->fillin('URL',encode_html(equal_url($config->{'httproot'},$virtual)));
+ $tpl->fillin('SCRIPT',$script);