debug-upload.pl 733 B

123456789101112131415161718192021222324252627
  1. #! /usr/bin/perl
  2. use CGI;
  3. use CGI::Carp;
  4. my $q = new CGI;
  5. print $q->header(),
  6. $q->start_html('File Upload'),
  7. $q->h1('File Upload');
  8. print $q->start_form(-method=>'GET'),
  9. $q->p('File: ', $q->filefield(-name=>'file', -size=>50, -maxlength=>100)),
  10. $q->p($q->submit()),
  11. $q->end_form();
  12. if ($q->param('file')) {
  13. my $file = $q->upload('file');
  14. if ($file) {
  15. print $q->p('Upload ok.');
  16. print $q->p('Name: ', $q->param('file'));
  17. print $q->p('Info: ', $q->uploadInfo($q->param('file')));
  18. print $q->p('Type: ', $q->uploadInfo($q->param('file'))->{'Content-Type'});
  19. } elsif (!$file && $q->cgi_error) {
  20. print $q->p('Error: ' . $q->cgi_error);
  21. } else {
  22. print $q->p('Weird.');
  23. }
  24. }
  25. print $q->end_html();