version 1.475, 2004/03/08 23:04:00
|
version 1.476, 2004/03/09 16:25:19
|
Line 1186 sub tokenwrapper {
|
Line 1186 sub tokenwrapper {
|
# output: url of file in userspace |
# output: url of file in userspace |
|
|
sub userfileupload { |
sub userfileupload { |
my ($formname,$coursedoc)=@_; |
my ($formname,$coursedoc,$filename,$fpath,$source)=@_; |
my $fname=$ENV{'form.'.$formname.'.filename'}; |
my $fname; |
|
if (defined($filename)) { |
|
$fname = $filename; |
|
} else { |
|
$fname=$ENV{'form.'.$formname.'.filename'}; |
|
} |
# Replace Windows backslashes by forward slashes |
# Replace Windows backslashes by forward slashes |
$fname=~s/\\/\//g; |
$fname=~s/\\/\//g; |
# Get rid of everything but the actual filename |
# Get rid of everything but the actual filename |
Line 1198 sub userfileupload {
|
Line 1203 sub userfileupload {
|
$fname=~s/[^\w\.\-]//g; |
$fname=~s/[^\w\.\-]//g; |
# See if there is anything left |
# See if there is anything left |
unless ($fname) { return 'error: no uploaded file'; } |
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 |
# Create the directory if not present |
my $docuname=''; |
my $docuname=''; |
my $docudom=''; |
my $docudom=''; |
Line 1213 sub userfileupload {
|
Line 1222 sub userfileupload {
|
$docuhome=$ENV{'user.home'}; |
$docuhome=$ENV{'user.home'}; |
} |
} |
return |
return |
&finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname); |
&finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname,$fpath,$source); |
} |
} |
|
|
sub finishuserfileupload { |
sub finishuserfileupload { |
my ($docuname,$docudom,$docuhome,$formname,$fname)=@_; |
my ($docuname,$docudom,$docuhome,$formname,$fname,$fpath,$source)=@_; |
my $path=$docudom.'/'.$docuname.'/'; |
my $path=$docudom.'/'.$docuname.'/'.$fpath; |
my $filepath=$perlvar{'lonDocRoot'}; |
my $filepath=$perlvar{'lonDocRoot'}; |
my @parts=split(/\//,$filepath.'/userfiles/'.$path); |
my @parts=split(/\//,$filepath.'/userfiles/'.$path); |
my $count; |
my $count; |
Line 1230 sub finishuserfileupload {
|
Line 1239 sub finishuserfileupload {
|
} |
} |
# Save the file |
# Save the file |
{ |
{ |
open(my $fh,'>'.$filepath.'/'.$fname); |
if ($source eq '') { |
print $fh $ENV{'form.'.$formname}; |
open(my $fh,'>'.$filepath.'/'.$fname); |
close($fh); |
print $fh $ENV{'form.'.$formname}; |
|
close($fh); |
|
} else { |
|
my $destination = $filepath.'/'.$fname; |
|
rename($source,$destination); |
|
} |
} |
} |
# Notify homeserver to grep it |
# Notify homeserver to grep it |
# |
# |
|
|
my $fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname, |
my $fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname. |
$docuhome); |
':'.$fpath,$docuhome); |
if ($fetchresult eq 'ok') { |
if ($fetchresult eq 'ok') { |
# |
# |
# Return the URL to it |
# Return the URL to it |