Module | ActionController::UploadedFile |
In: |
vendor/rails/actionpack/lib/action_controller/request.rb
|
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 728 728: def self.included(base) 729: base.class_eval do 730: attr_accessor :original_path, :content_type 731: alias_method :local_path, :path 732: end 733: end
Take the basename of the upload‘s original filename. This handles the full Windows paths given by Internet Explorer (and perhaps other broken user agents) without affecting those which give the lone filename. The Windows regexp is adapted from Perl‘s File::Basename.
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 740 740: def original_filename 741: unless defined? @original_filename 742: @original_filename = 743: unless original_path.blank? 744: if original_path =~ /^(?:.*[:\\\/])?(.*)/m 745: $1 746: else 747: File.basename original_path 748: end 749: end 750: end 751: @original_filename 752: end