--- loncom/publisher/lonupload.pm 2002/08/08 02:30:39 1.12 +++ loncom/publisher/lonupload.pm 2002/08/24 03:56:58 1.13 @@ -2,7 +2,7 @@ # The LearningOnline Network with CAPA # Handler to upload files into construction space # -# $Id: lonupload.pm,v 1.12 2002/08/08 02:30:39 foxr Exp $ +# $Id: lonupload.pm,v 1.13 2002/08/24 03:56:58 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,10 +53,12 @@ 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; @@ -104,7 +106,10 @@ sub phaseone { $fn.=$ENV{'form.upfile.filename'}; $fn=~s/^\///; $fn=~s/(\/)+/\//g; - $fn=~s/%20/ /g; + +# Fn is the full path to the destination filename. +# + &Debug($r, "Filename for upload: $fn"); if (($fn) && ($fn!~/\/$/)) { $r->print( @@ -143,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')) { @@ -154,7 +169,7 @@ sub phasetwo { '
'. 'File '.$fn.' exists. Overwrite? '. ''. - ''. + ''. ''. '
'); } else { @@ -178,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: '.$!);