|
|
@ -35,9 +35,9 @@ class Attachment < ActiveRecord::Base |
|
|
|
errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes |
|
|
|
errors.add_to_base :too_long if self.filesize > Setting.attachment_max_size.to_i.kilobytes |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def file=(incomming_file) |
|
|
|
def file=(incoming_file) |
|
|
|
unless incomming_file.nil? |
|
|
|
unless incoming_file.nil? |
|
|
|
@temp_file = incomming_file |
|
|
|
@temp_file = incoming_file |
|
|
|
if @temp_file.size > 0 |
|
|
|
if @temp_file.size > 0 |
|
|
|
self.filename = sanitize_filename(@temp_file.original_filename) |
|
|
|
self.filename = sanitize_filename(@temp_file.original_filename) |
|
|
|
self.disk_filename = DateTime.now.strftime("%y%m%d%H%M%S") + "_" + self.filename |
|
|
|
self.disk_filename = DateTime.now.strftime("%y%m%d%H%M%S") + "_" + self.filename |
|
|
@ -87,7 +87,7 @@ class Attachment < ActiveRecord::Base |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def image? |
|
|
|
def image? |
|
|
|
self.filename =~ /\.(jpeg|jpg|gif|png)$/i |
|
|
|
self.filename =~ /\.(jpe?g|gif|png)$/i |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
@ -97,8 +97,7 @@ private |
|
|
|
# NOTE: File.basename doesn't work right with Windows paths on Unix |
|
|
|
# NOTE: File.basename doesn't work right with Windows paths on Unix |
|
|
|
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/')) |
|
|
|
# INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/')) |
|
|
|
|
|
|
|
|
|
|
|
# Finally, replace all non alphanumeric, underscore or periods with underscore |
|
|
|
# Finally, replace all non alphanumeric, hyphens or periods with underscore |
|
|
|
@filename = just_filename.gsub(/[^\w\.\-]/,'_') |
|
|
|
@filename = just_filename.gsub(/[^\w\.\-]/,'_') |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|