diff options
| author | ivan <ivan> | 2008-08-14 11:56:12 +0000 |
|---|---|---|
| committer | ivan <ivan> | 2008-08-14 11:56:12 +0000 |
| commit | a9d755c3cee7542d3ca552174af0b7b71693ae58 (patch) | |
| tree | 30554127a48140e35d59aa015bbf3dd3d4f1ab18 /httemplate/misc/file-upload.html | |
| parent | b4544738ea893d0e2504d36bc1cd3d0bd369b31e (diff) | |
customer import: add progress bar & redirect to a search of the imported customers, #3475
Diffstat (limited to 'httemplate/misc/file-upload.html')
| -rw-r--r-- | httemplate/misc/file-upload.html | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/httemplate/misc/file-upload.html b/httemplate/misc/file-upload.html new file mode 100644 index 000000000..469274c69 --- /dev/null +++ b/httemplate/misc/file-upload.html @@ -0,0 +1,53 @@ +<% include('/elements/header-minimal.html', 'File Upload') %> +% if ($error) { +Error: <% $error %> +% }else{ +File Upload Successful <% join(',', @filenames) %>; +% } +<% include('/elements/footer.html') %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Import'); #? + +my @filenames = (); +my $error = ''; # could be extended to the access control + +$cgi->param('upload_fields') =~ /^([,\w]+)$/ + or $error = "invalid upload_fields"; +my $fields = $1; + +my $dir = $FS::UID::cache_dir. "/cache.". $FS::UID::datasrc; + +foreach my $field (split /,/, $fields) { + next if $error; + + my $fh = $cgi->upload($field) + or $error = "No valid file was provided."; + + my $suffix = ''; + if ( $cgi->param($field) =~ /(\.\w+)$/i ) { + $suffix = lc($1); + } + + my $sh = new File::Temp( TEMPLATE => 'upload.XXXXXXXX', + SUFFIX => $suffix, + DIR => $dir, + UNLINK => 0, + ) + or $error ||= "can't open temporary file to store upload: $!\n"; + + unless ($error) { + while(<$fh>) { + print $sh $_; + } + $sh->filename =~ m!.*/([.\w]+)$!; + push @filenames, "$field:$1"; + close $sh + } + +} + +$error = "No files" unless scalar(@filenames); + +</%init> |
