home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / asp / file_upload.asp < prev    next >
Encoding:
Text File  |  2003-09-03  |  2.4 KB  |  91 lines

  1. #!/usr/bin/perl /usr/bin/asp-perl
  2.  
  3. <!--#include file="header.inc"-->
  4.  
  5. This example shows you how to use Apache::ASP to handle file uploads.
  6. You need to have a recent version CGI.pm to use this facility.
  7. Just click Browse..., select your file, hit 'file upload' and 
  8. voila!, you will see the data in the file below.
  9. <p>
  10. Note that the current limit set on uploads for this demo is
  11. <tt>    
  12. <%
  13. my $limit = $Server->Config('FileUploadMax') || $CGI::POST_MAX;
  14. $limit = ($limit eq '-1') ? 'NONE' : $limit;
  15. print "$limit";
  16. %>
  17. </tt>.
  18. <% if($limit && ($limit < $Request->{TotalBytes})) { %>
  19.   This limit was <b>exceeded</b> by a POST of <tt><%= $Request->{TotalBytes} %></tt> bytes!
  20. <% } %>
  21. <table border=0><tr><td valign=center>
  22. <%
  23. use CGI;
  24. my $q = new CGI; 
  25. print $q->start_multipart_form();
  26. print $q->hidden('file_upload', 'Hidden File Upload Form Text');
  27. print $q->filefield('uploaded_file','starting value',30,100);
  28. print "</td><td valign=center>";
  29. print $q->submit('Upload File');
  30. %>
  31. </td></tr></table>
  32.  
  33. <br>
  34. <b>File Upload Type:</b>
  35. <%= 
  36.     $q->checkbox_group(-name=>'extensions',
  37.            -values=>['GIF','HTML','OTHER'],
  38.            -defaults=>['HTML']
  39.            ).
  40.     $q->endform()
  41.   %>
  42.  
  43. <% 
  44. my $filehandle;
  45. if($filehandle = $Request->{Form}{uploaded_file}) { 
  46.     %>
  47.       Upload Type Specified: <%= join(', ', $Request->Form('extensions')) %><br>
  48.     <%
  49.     local *FILE;
  50.     my $upload = $Request->{FileUpload}{uploaded_file};
  51.     print "<table>";
  52.     my @data = (
  53.         '$Request->{TotalBytes}', $Request->{TotalBytes},
  54.         'Hidden Text', $Request->Form('file_upload'),
  55.         'Uploaded File Name', $filehandle,
  56.         # we only have the temp file because of the
  57.         # FileUploadTemp setting
  58.         'Temp File', $upload->{TempFile},
  59.         'Temp File Exists', (-e $upload->{TempFile}),
  60.         'Temp File Opened', (open(FILE, $upload->{TempFile}) ? 'yes' : "no: $!"),
  61.         map { 
  62.             ($_, $Request->FileUpload('uploaded_file', $_)) 
  63.         } sort keys %$upload 
  64.            );
  65.     close FILE;
  66.  
  67.     while(@data) {
  68.     my($key, $value) = (shift @data, shift @data);
  69.         %>
  70.         <tr>
  71.             <td><b><font size=-1><%=$key%></font></b></td>
  72.             <td><font size=-1><%=$value%></font></td>
  73.         </tr>
  74.         <%
  75.     }
  76.     print "</table>";
  77.     %>
  78.  
  79.     <pre>
  80. UPLOADED DATA
  81. =============
  82. <% 
  83.     while(<$filehandle>) { 
  84.     print $Server->HTMLEncode($_);    
  85.     }
  86. %>
  87.     </pre>
  88. <% } %>
  89.  
  90. <!--#include file="footer.inc"-->
  91.