#!/usr/bin/perl -w # Written by Paris Sinclair, aka Aighearach, march 2000 # freed to the public domain use strict; use CGI qw( :standard :html ); # You will need to change these to set up your page use constant UPLOAD_DIR => '/home/paris/public_html/files/'; use constant RELATIVE_DIR => 'files/'; use constant TITLE => "Lauren's Internet Media Center"; # nothing more to edit my ( $uploaded_file, $url ); print header(), start_html(), center(), h1( TITLE ); # is this the index? if ( param() ) { # no, so are we uploading or deleteing? if ( my $file = param('delete') ) { # deleting. You may want to add an or print STDERR "can't delete $file\n"; # to this I left that out because I don't want the errors in the apache logs - that's # for the mission critical programs, so I just print the error to the page unlink( RELATIVE_DIR.$file ) || print "error unlinking $file"; } elsif ( my $uploaded_file = param('uploaded_file') ) { # uploading. make it something cool my $full_name = UPLOAD_DIR . $uploaded_file; open ( OUT, ">$full_name") || print "error writing $full_name"; my $buffer; while ( read( $uploaded_file, $buffer, 1024 ) ) { print OUT $buffer; } #Delete('uploaded_file'); } } print table( {-border=>0,-align=>"center"}, file_list() ), table( {-border=>0,-align=>"center"}, Tr( [ td( upload_form() ) ] ) ); ### returns upload form sub upload_form { return start_multipart_form( -action=>url() ) . "upload:" . filefield( -name=>'uploaded_file', -default=>'', -size=>50, -maxlength=>100 ) . submit( -name=>'upload', -value=>'upload' ) . end_multipart_form(); } ### returns table rows, so make sure you're in a table sub file_list { my $file; my $dir = UPLOAD_DIR; my $output; # it may be better to open the dir by hand, but in the context # it was written for, the performance difference is irrelevant foreach $file ( `ls $dir` ) { chomp($file); my $full_file = $dir . $file; my $size = (stat("$full_file"))[7]; $output .= Tr( td( [ a( {-href=>RELATIVE_DIR.$file},$file ), # this part could use some work. In particular, # it should label large files in megs. int($size/1024) . 'K', a( {-href=>url()."?delete=$file"}, "delete" ) ] ) ); }; return $output; }