File: file_upload.asp

package info (click to toggle)
libapache-asp-perl 2.63-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,120 kB
  • sloc: perl: 6,044; php: 409; sh: 62; lisp: 22; makefile: 10
file content (90 lines) | stat: -rwxr-xr-x 2,309 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl /usr/bin/asp-perl

<!--#include file="header.inc"-->

This example shows you how to use Apache::ASP to handle file uploads.
You need to have a recent version CGI.pm to use this facility.
Just click Browse..., select your file, hit 'file upload' and 
voila!, you will see the data in the file below.
<p>
Note that the current limit set on uploads for this demo is
<tt>	
<%
my $limit = $Server->Config('FileUploadMax') || $CGI::POST_MAX;
$limit = ($limit eq '-1') ? 'NONE' : $limit;
print "$limit";
%>
</tt>.
<% if($limit && ($limit < $Request->{TotalBytes})) { %>
  This limit was <b>exceeded</b> by a POST of <tt><%= $Request->{TotalBytes} %></tt> bytes!
<% } %>
<table border=0><tr><td valign=center>
<%
use CGI;
my $q = new CGI; 
print $q->start_multipart_form();
print $q->hidden('file_upload', 'Hidden File Upload Form Text');
print $q->filefield('uploaded_file','starting value',30,100);
print "</td><td valign=center>";
print $q->submit('Upload File');
%>
</td></tr></table>

<br>
<b>File Upload Type:</b>
<%= 
    $q->checkbox_group(-name=>'extensions',
		   -values=>['GIF','HTML','OTHER'],
		   -defaults=>['HTML']
		   )
  %>
</form>   

<% 
my $filehandle;
if($filehandle = $Request->{Form}{uploaded_file}) { 
    %>
      Upload Type Specified: <%= join(', ', $Request->Form('extensions')) %><br>
    <%
    local *FILE;
    my $upload = $Request->{FileUpload}{uploaded_file};
    print "<table>";
    my @data = (
		'$Request->{TotalBytes}', $Request->{TotalBytes},
		'Hidden Text', $Request->Form('file_upload'),
		'Uploaded File Name', $filehandle,
		# we only have the temp file because of the
		# FileUploadTemp setting
		'Temp File', $upload->{TempFile},
		'Temp File Exists', (-e $upload->{TempFile}),
		'Temp File Opened', (open(FILE, $upload->{TempFile}) ? 'yes' : "no: $!"),
		map { 
		    ($_, $Request->FileUpload('uploaded_file', $_)) 
		} sort keys %$upload 
	       );
    close FILE;

    while(@data) {
	my($key, $value) = (shift @data, shift @data);
		%>
		<tr>
			<td><b><font size=-1><%=$key%></font></b></td>
			<td><font size=-1><%=$value%></font></td>
		</tr>
		<%
    }
    print "</table>";
	%>

	<pre>
UPLOADED DATA
=============
<% 
    while(<$filehandle>) { 
	print $Server->HTMLEncode($_);	
    }
%>
	</pre>
<% } %>

<!--#include file="footer.inc"-->