--- loncom/publisher/lonupload.pm 2002/08/05 02:22:56 1.11 +++ loncom/publisher/lonupload.pm 2002/08/24 03:56:58 1.13 @@ -1,7 +1,8 @@ + # The LearningOnline Network with CAPA # Handler to upload files into construction space # -# $Id: lonupload.pm,v 1.11 2002/08/05 02:22:56 foxr Exp $ +# $Id: lonupload.pm,v 1.13 2002/08/24 03:56:58 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,9 +53,29 @@ package Apache::lonupload; use strict; use Apache::File; use File::Copy; +use File::Basename; use Apache::Constants qw(:common :http :methods); use Apache::loncacc; use Apache::loncommon(); +use Apache::Log(); +use Apache::lonnet; + +my $DEBUG=0; + +sub Debug { + + # Marshall the parameters. + + my $r = shift; + my $log = $r->log; + my $message = shift; + + # Put out the indicated message butonly if DEBUG is false. + + if ($DEBUG) { + $log->debug($message); + } +} sub upfile_store { my $r=shift; @@ -86,6 +107,10 @@ sub phaseone { $fn=~s/^\///; $fn=~s/(\/)+/\//g; +# Fn is the full path to the destination filename. +# + + &Debug($r, "Filename for upload: $fn"); if (($fn) && ($fn!~/\/$/)) { $r->print( '
'. @@ -123,10 +148,20 @@ sub phaseone { sub phasetwo { my ($r,$fn,$uname,$udom)=@_; - if ($fn=~/^\/priv\/$uname\//) { + &Debug($r, "Filename is ".$fn); + if ($fn=~/^\/priv\/$uname\//) { + &Debug($r, "Filename after priv substitution: ".$fn); my $tfn=$fn; $tfn=~s/^\/(\~|priv)\/(\w+)//; + &Debug($r, "Filename for tfn = ".$tfn); my $target='/home/'.$uname.'/public_html'.$tfn; + &Debug($r, "target -> ".$target); +# target is the full filesystem path of the destination file. + my $base = &File::Basename::basename($fn); + my $path = &File::Basename::dirname($fn); + $base = Apache::lonnet::escape($base); + my $url = $path."/".$base; + &Debug($r, "URL is now ".$url); my $datatoken=$ENV{'form.datatoken'}; if (($fn) && ($datatoken)) { if ((-e $target) && ($ENV{'form.override'} ne 'Yes')) { @@ -134,7 +169,7 @@ sub phasetwo { ''. 'File '.$fn.' exists. Overwrite? '. ''. - ''. + ''. ''. '
'); } else { @@ -158,7 +193,7 @@ sub phasetwo { } elsif (copy($source,$target)) { chmod(0660, $target); # Set permissions to rw-rw---. $r->print('File copied.'); - $r->print('

View file'); } else { $r->print('Failed to copy: '.$!);