| Module | ActionController::UploadedFile |
| In: |
vendor/rails/actionpack/lib/action_controller/request.rb
|
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 731
731: def self.included(base)
732: base.class_eval do
733: attr_accessor :original_path, :content_type
734: alias_method :local_path, :path
735: end
736: 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 743
743: def original_filename
744: unless defined? @original_filename
745: @original_filename =
746: unless original_path.blank?
747: if original_path =~ /^(?:.*[:\\\/])?(.*)/m
748: $1
749: else
750: File.basename original_path
751: end
752: end
753: end
754: @original_filename
755: end