--- loncom/lonnet/perl/lonnet.pm 2002/07/30 19:59:32 1.256 +++ loncom/lonnet/perl/lonnet.pm 2002/07/31 13:50:38 1.258 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.256 2002/07/30 19:59:32 albertel Exp $ +# $Id: lonnet.pm,v 1.258 2002/07/31 13:50:38 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -717,6 +717,36 @@ sub tokenwrapper { 'token='.$token.'&server='.$perlvar{'lonHostID'}; } +# --------------- Take an uploaded file and put it into the userfiles directory +# input: name of form element +# output: url of file in userspace + +sub userfileupload { + my $formname=shift; + my $fname=$ENV{'form.'.$formname.'.filename'}; + $fname=~s/\\/\//g; + $fname=~s/^.*\/([^\/]+)$/$1/; + unless ($fname) { return 'error: no uploaded file'; } + chop($ENV{'form.'.$formname}); +# Create the directory if not present + my $path='/userfiles/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/'; + my $filepath=$perlvar{'lonDocRoot'}; + my @parts=split(/\//,$filepath.$path); + my $count; + for ($count=4;$count<=$#parts;$count++) { + $filepath.="/$parts[$count]"; + if ((-e $filepath)!=1) { + mkdir($filepath,0777); + } + } +# Save the file + { + my $fh=Apache::File->new('>'.$filepath.'/'.$fname); + print $fh $ENV{'form.'.$formname}; + } +# Return the URL to it + return 'http://'.$ENV{'SERVER_NAME'}.$path.$fname; +} # ------------------------------------------------------------------------- Log