Module | ActionController::UploadedFile |
In: |
vendor/rails/actionpack/lib/action_controller/request.rb
|
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 848 848: def self.included(base) 849: base.class_eval do 850: attr_accessor :original_path, :content_type 851: alias_method :local_path, :path 852: end 853: 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 860 860: def original_filename 861: unless defined? @original_filename 862: @original_filename = 863: unless original_path.blank? 864: if original_path =~ /^(?:.*[:\\\/])?(.*)/m 865: $1 866: else 867: File.basename original_path 868: end 869: end 870: end 871: @original_filename 872: end