--- loncom/publisher/lonupload.pm 2001/04/05 19:35:15 1.1 +++ loncom/publisher/lonupload.pm 2001/04/10 01:57:28 1.2 @@ -15,7 +15,7 @@ # # 03/31,04/03 Gerd Kortemeyer) # -# 04/05 Gerd Kortemeyer +# 04/05,04/09 Gerd Kortemeyer package Apache::lonupload; @@ -24,94 +24,67 @@ use Apache::File; use File::Copy; use Apache::Constants qw(:common :http :methods); -sub phaseone { - my ($r,$fn,$uname,$udom)=@_; - my $docroot=$r->dir_config('lonDocRoot'); - - my $urldir='/res/'.$udom.'/'.$uname.$fn; - $urldir=~s/\/[^\/]+$/\//; - my $resfn=$docroot.'/res/'.$udom.'/'.$uname.$fn; - my $resdir=$resfn; - $resdir=~s/\/[^\/]+$/\//; - - $fn=~/^\/(.+)\.(\w+)$/; - my $main=$1; - my $suffix=$2; +sub upfile_store { + my $r=shift; + + my $fname=$ENV{'form.upfile.filename'}; + $fname=~s/\W//g; + + chop($ENV{'form.upfile'}); - $r->print('
'); + return $datatoken; +} + + +sub phaseone { + my ($r,$fn,$uname,$udom)=@_; + $fn=~s/\/[^\/]+$//; + $fn=~s/([^\/])$/$1\//; + $fn.=$ENV{'form.upfile.filename'}; + $r->print( + ''); } sub phasetwo { my ($r,$fn,$uname,$udom)=@_; - if ($ENV{'form.version'}) { - my $version=$ENV{'form.version'}; - if ($version eq 'new') { - $r->print('Copying file: '); - if (copy($csource,$ctarget)) { - $r->print('ok
'); - print $logfile "Copied sucessfully.\n\n"; - } else { - my $error=$!; - $r->print('fail, '.$error.'
'); - print $logfile "Copy failed: $error\n\n"; - } - $r->print('Back to '.$fn.''); + my $target='/home/'.$uname.'/public_html'.$fn; + my $datatoken=$ENV{'form.datatoken'}; + if (($fn) && ($datatoken)) { + if ((-e $target) && ($ENV{'form.override'} ne 'Yes')) { + $r->print( + '
'); + } else { + my $source=$r->dir_config('lonDaemons'). + '/tmp/'.$datatoken.'.tmp'; + if (copy($source,$target)) { + $r->print('File copied.'); + $r->print('View file'); + } else { + $r->print('Failed to copy: '.$!); + } + } } else { $r->print( - 'Please pick a version to retrieve
'); + 'Please pick a filename
'); &phaseone($r,$fn,$uname,$udom); } } @@ -127,16 +100,10 @@ sub handler { $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)//; } else { $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. - ' unspecified filename for retrieval', $r->filename); + ' unspecified filename for upload', $r->filename); return HTTP_NOT_FOUND; } - unless ($fn) { - $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. - ' trying to retrieve non-existing file', $r->filename); - return HTTP_NOT_FOUND; - } - # ----------------------------------------------------------- Start page output my $uname=$ENV{'user.name'}; @@ -151,7 +118,7 @@ sub handler { '
'); - $r->print('