--- loncom/lonnet/perl/lonnet.pm 2004/03/08 23:04:00 1.475 +++ loncom/lonnet/perl/lonnet.pm 2004/03/09 16:25:19 1.476 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.475 2004/03/08 23:04:00 albertel Exp $ +# $Id: lonnet.pm,v 1.476 2004/03/09 16:25:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1186,8 +1186,13 @@ sub tokenwrapper { # output: url of file in userspace sub userfileupload { - my ($formname,$coursedoc)=@_; - my $fname=$ENV{'form.'.$formname.'.filename'}; + my ($formname,$coursedoc,$filename,$fpath,$source)=@_; + my $fname; + if (defined($filename)) { + $fname = $filename; + } else { + $fname=$ENV{'form.'.$formname.'.filename'}; + } # Replace Windows backslashes by forward slashes $fname=~s/\\/\//g; # Get rid of everything but the actual filename @@ -1198,7 +1203,11 @@ sub userfileupload { $fname=~s/[^\w\.\-]//g; # See if there is anything left unless ($fname) { return 'error: no uploaded file'; } - chop($ENV{'form.'.$formname}); + if ( defined($formname) ) { + if ( defined($ENV{'form.'.$formname}) ) { + chop($ENV{'form.'.$formname}); + } + } # Create the directory if not present my $docuname=''; my $docudom=''; @@ -1213,12 +1222,12 @@ sub userfileupload { $docuhome=$ENV{'user.home'}; } return - &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname); + &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname,$fpath,$source); } sub finishuserfileupload { - my ($docuname,$docudom,$docuhome,$formname,$fname)=@_; - my $path=$docudom.'/'.$docuname.'/'; + my ($docuname,$docudom,$docuhome,$formname,$fname,$fpath,$source)=@_; + my $path=$docudom.'/'.$docuname.'/'.$fpath; my $filepath=$perlvar{'lonDocRoot'}; my @parts=split(/\//,$filepath.'/userfiles/'.$path); my $count; @@ -1230,15 +1239,20 @@ sub finishuserfileupload { } # Save the file { - open(my $fh,'>'.$filepath.'/'.$fname); - print $fh $ENV{'form.'.$formname}; - close($fh); + if ($source eq '') { + open(my $fh,'>'.$filepath.'/'.$fname); + print $fh $ENV{'form.'.$formname}; + close($fh); + } else { + my $destination = $filepath.'/'.$fname; + rename($source,$destination); + } } # Notify homeserver to grep it # - my $fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname, - $docuhome); + my $fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname. + ':'.$fpath,$docuhome); if ($fetchresult eq 'ok') { # # Return the URL to it