The Open Source Swiss Army Knife

/miscellany/alex/
/miscellany/alex/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /miscellany   /alex 
Permalink: code.pm
Title: alexs files
article options : please login   |  raw source view  

package Apache::NewUpload;
here we go
use Apache::Constants ':common';
use Apache::Constants 'REDIRECT';
use Apache::Utility;
use File::Basename;
use CGI qw(:standard);
use Apache::Filter;
use Apache::DbiHandle;
use Apache::NewUser;
use Apache::FileTitle;
use strict;

sub handler {
	my $r = shift;
	$r = $r->filter_register();
	$r->notes('up_button' => 'no');
	$r->notes('edit_this_file_link' => 'no');
	my %hash;
	my ($rv);
	$hash{'title'} = $r->notes->{'title'};
	$hash{'submit'} = $r->notes->{'submit'};
	$hash{'user_location'} = $r->notes->{'user_location'};
	$hash{'newupload_filebody'} = $r->notes->{'newupload_filebody'};
	$hash{'user_location_path'} = $r->notes->{'user_location_path'};
	$hash{'cookie_uname'} = $r->notes->{'cookie_uname'};
	$hash{'newupload_filename'} = $r->notes->{'newupload_filename'};

	$hash{'fullpath'} = "/var/sirfsup" . $hash{'user_location_path'};

	if ($hash{'cookie_uname'} eq "") { 
		&Apache::NewUser::present_first($r, $r->notes->{'user_location'});
	} elsif ($hash{'cookie_uname'} eq "anonymous") { 
		&Apache::NewUser::present_perms_no("you should log back in and try again", $hash{'user_location'});
	} elsif ($hash{'submit'} eq "" ) {
		$rv = &Apache::Utility::check_upload_perms($r, $hash{'fullpath'});
		if ($rv eq "no") {
			&Apache::Utility::present_perms_no("invalid permissions",$hash{'user_location'});
		} else {
			present_first($r, \%hash);
		}
	} elsif ($hash{'submit'} ne "" ) {
		$rv = &Apache::Utility::check_upload_perms($r, $hash{'fullpath'});
		if ($rv eq "no") {
			&Apache::Utility::present_perms_no("invalid permissions",$hash{'user_location'});
		} else {
			present_second ($r, \%hash);
		}
	} 
	return OK;
} # end handler

sub present_first {
	my $r = shift;
	my $hash_in = shift;
	my $server_name = $r->get_server_name;
	print qq~<p><form method=post action="http://www.sirfsup.com/newupload" enctype="multipart/form-data">~;
	print qq~<br><input type=hidden name="user_location" value="$hash_in->{'user_location'}">~;
	print qq~<p>File upload location: <b>$hash_in->{'user_location_path'}</b>~;
	print qq~<p>(the upload location will be difficult to choose at this time so please browse around before placing your file)~;
	print qq~<p>title: <input type=text name=title maxlength=100 size=100>~;
	print qq~<p>File to upload: <input type="file" name="newupload">~;

	print qq~<p><input type='submit' name='submit' value='upload file to directory'>~;
	print qq~</form><br><br><br>~;
} 


sub present_second {
	my $r = shift;
	my $hash_in = shift;
	my %hash = %$hash_in;
	my $server_name = $r->get_server_name;
	# database
	my ($file, $rv);
	$file = $hash{'newupload_filebody'};
	my $upload_directory = "/var/sirfsup " .  $hash{'user_location_path'};
	my $upload_location = "/var/sirfsup" .  $hash{'user_location_path'} . $hash{'newupload_filename'};
	my $return_url =  $hash{'user_location_path'} . $hash{'newupload_filename'};
	$rv = &Apache::Utility::check_upload_perms($r, $hash{'upload_directory'});
	if ($rv eq "no") {
		&Apache::Utility::present_perms_no("invalid permissions",$hash{'user_location'});
	} else {
		my $success = new IO::File;
		$success->open(">$upload_location") or die("NewUpload: present_second: error opening for writing $upload_location error");
		$success->print($file);
		$success->close();

		$success->open("</usr/local/lib/Apache/fileedit_success.htm") or die("NewUpload: present_second: fileedit_success.htm opening error");
		while  (<$success>)  {
			s/<!--return_url--!>/$return_url/;
			print $_;
		}
		$success->close();
	}	
} # end present_second


1;

__END__

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top