@@ -, +, @@ --- reports/report_files.pl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/reports/report_files.pl +++ a/reports/report_files.pl @@ -29,6 +29,7 @@ use C4::Context; use C4::Output; use C4::Koha; use File::stat; +use Digest::MD5 qw(md5_hex); my $input = new CGI; my $file_id = $input->param("id"); @@ -50,8 +51,8 @@ else { my @files_list; opendir(DIR, $directory); - my $i=0; foreach my $filename (readdir(DIR)) { + my $id = md5_hex($filename); my $full_path = "$directory/$filename"; next if ($filename =~ /^\./ or -d $full_path); @@ -59,14 +60,14 @@ else { push(@files_list, {name => $filename, date => scalar localtime($st->mtime), size => $st->size, - id => $i}); - $i++; + id => $id}); } closedir(DIR); + my %files_hash = map { $_->{id} => $_ } @files_list; # If we received a file_id and it is valid, send the file to the browser - if(defined $file_id and $file_id >= 0 and $file_id < scalar @files_list){ - my $filename = $files_list[$file_id]->{name}; + if(defined $file_id and $file_id >= 0 and exists $files_hash{$file_id} ){ + my $filename = $files_hash{$file_id}->{name}; binmode STDOUT; # Open the selected file and send it to the browser print $input->header(-type => 'application/x-download', --