[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

www lon-capa-cvs@mail.lon-capa.org
Sat, 17 Aug 2002 18:58:29 -0000


www		Sat Aug 17 14:58:29 2002 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  &getfile can get userfiles
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.268 loncom/lonnet/perl/lonnet.pm:1.269
--- loncom/lonnet/perl/lonnet.pm:1.268	Sat Aug 17 14:23:27 2002
+++ loncom/lonnet/perl/lonnet.pm	Sat Aug 17 14:58:28 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.268 2002/08/17 18:23:27 www Exp $
+# $Id: lonnet.pm,v 1.269 2002/08/17 18:58:28 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3082,13 +3082,24 @@
 # ------------------------------------------------------------ Serves up a file
 # returns either the contents of the file or a -1
 sub getfile {
-  my $file=shift;
+ my $file=shift;
+ if ($file=~/^\/*uploaded\//) { # user file
+    my $ua=new LWP::UserAgent;
+    my $request=new HTTP::Request('GET',&tokenwrapper($file));
+    my $response=$ua->request($request);
+    if ($response->is_success()) {
+       return $response->content;
+    } else { 
+       return -1; 
+    }
+ } else { # normal file from res space
   &repcopy($file);
   if (! -e $file ) { return -1; };
   my $fh=Apache::File->new($file);
   my $a='';
   while (<$fh>) { $a .=$_; }
-  return $a
+  return $a;
+ }
 }
 
 sub filelocation {