');
return;
}
+ # Check if quota exceeded
+ my $filesize = length($env{'form.upfile'});
+ if (!$filesize) {
+ $r->print('
'.
+ &mt('Unable to upload [_1]. (size = [_2] bytes)',
+ ''.$env{'form.upfile.filename'}.'',
+ $filesize).' '.
+ &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').' '.
+ '
'.
+ &earlyout($fn,$uname,$udom));
+ return;
+ }
+ $filesize = int($filesize/1000); #expressed in kb
+ my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in Mb
+ $disk_quota = int($disk_quota * 1000);
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
+ if (($current_disk_usage + $filesize) > $disk_quota){
+ $r->print(''.
+ &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.',''.$env{'form.upfile.filename'}.'',$filesize).''.
+ ' '.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).
+ ''.
+ &earlyout($fn,$uname,$udom));
+ return;
+ }
+
# Split part that I can change from the part that I cannot change
my ($fn1,$fn2)=($fn=~/^(\/priv\/[^\/]+\/[^\/]+\/)(.*)$/);
# Display additional options for upload
@@ -240,7 +265,7 @@ sub phaseone {
}
sub phasetwo {
- my ($r,$fn,$uname,$udom,$mode)=@_;
+ my ($r,$fn,$mode)=@_;
my $output;
my $action = '/adm/upload';
@@ -252,7 +277,7 @@ sub phasetwo {
}
$fn=~s/\/+/\//g;
if ($fn) {
- my $target='/home/httpd/html/'.$fn;
+ my $target= $r->dir_config('lonDocRoot').'/'.$fn;
&Debug($r, "target -> ".$target);
# target is the full filesystem path of the destination file.
my $base = &File::Basename::basename($fn);
@@ -406,8 +431,8 @@ sub phasethree {
}
my $url_root = "/priv/$udom/$uname";
my $dir_root = $r->dir_config('lonDocRoot').$url_root;
- my $url_root = '/priv/'.$udom.'/'.$uname;
my $path = &File::Basename::dirname($fn);
+ $path =~ s{^\Q$url_root\E}{};
my $filename = &HTML::Entities::encode($env{'form.filename'},'<>&"');
my $state = &embedded_form_elems('modify_orightml',$filename,$mode).
'';
@@ -416,7 +441,7 @@ sub phasethree {
$dir_root,$url_root,undef,
undef,undef,$state,$action);
if ($mode ne 'imsimport' && $mode ne 'testbank') {
- $result .= '