Mon 22 Jun 2009
When you upload a file in ruby, from IE, you get the full path when you do temp_file.original_filename or filename. You are supposed to be able to use File.basename(filename) from ruby to strip that out - but it doesn’t really work b/c if you are running in linux and someone from windows uploads a file in I.e. (a highly likely scenario) - the path delimiters for linux don’t jive with the path delimiters for windows, and so - it doesn’t work.
I ended up using Rick Olson’s attachement_fu code instead.
The relevant bit here:
def sanitize_filename(filename)
returning filename.strip do |name|
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
name.gsub! /^.*(\\|\/)/, ''
# Finally, replace all non alphanumeric, underscore or periods with underscore
name.gsub! /[^\w\.\-]/, '_'
end
end
December 11th, 2009 at 7:26 am
I love cashing in totally free casino chips online. I started getting free casino chips about 1 year ago and it’s a fun way to play at casino without breaking the bank. I’ve redeemed about 3K since starting! I love free money!