Ignore:
Timestamp:
2009-01-06T18:40:53+13:00 (15 years ago)
Author:
ak19
Message:

Now plugins provide the option of base64 encoding or url encoding filenames that are to be renamed (when copied into the archives dir). Previously renamed files would always be url-encoded. URL-encoding is the default now for most plugins except MP3Plugin and OggVorbisPlugin, where the default is base64 encoding. Base64 encoding filenames upon renaming them was introduced so that more files that browsers try to open in external applications can open them, since url encoding does not seem to be implemented the same everywhere (for instance, windows media player is unable to handle url-encoded wmv filenames when such files are launched in it through the browser).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/util.pm

    r17714 r18319  
    2828use File::Copy;
    2929use File::Basename;
     30use MIME::Base64; # for base64 encoding
    3031
    3132use strict;
     
    994995}
    995996
     997# returns the given filename converted using either URL encoding or
     998# base64 encoding, as specified by $rename_method
     999sub rename_file {
     1000    my ($filename, $rename_method)  = @_;
     1001   
     1002    my ($tailname,$dirname,$suffix) = File::Basename::fileparse($filename, "\\.[^\\.]+\$");
     1003
     1004    if (!$rename_method) {
     1005    print STDERR "WARNING: no file renaming method specified. Defaulting to using URL encoding...\n";
     1006    # Debugging information
     1007    my ($cpackage,$cfilename,$cline,$csubr,$chas_args,$cwantarray) = caller(1);
     1008    print STDERR "Calling method; $cfilename:$cline $cpackage->$csubr\n";
     1009    }
     1010
     1011    if (!$rename_method || $rename_method eq "url") {
     1012    $tailname = &unicode::url_encode($tailname);
     1013    }
     1014    elsif ($rename_method eq "base64") {
     1015    $tailname = &MIME::Base64::encode_base64($tailname);
     1016    $tailname =~ s/\s*//sg;      # for some reason it adds spaces not just at end but also in middle
     1017    }
     1018       
     1019    $filename = "$tailname$suffix";
     1020    $filename = "$dirname$filename" if ($dirname ne "./");
     1021
     1022    return $filename;
     1023}
     1024
    99610251;
Note: See TracChangeset for help on using the changeset viewer.