[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Handling binary files with mod_ruby and cgi

zak.wilson

1/3/2008 6:48:00 AM

I'm trying to write a CGI script that will fetch a named file and send
it back to the browser. No matter what output method I use, it's
writing two newlines to the end of the file, which corrupts many
binary file formats. I'm sure I'm missing something obvious. Here's a
simple version of the script (yes, I'm aware it can be used to read
any file on the system - the full version sanitizes the filename and
restricts access to a specific directory):

require 'mime/types'
cgi = CGI.new()
file = cgi['file'].untaint
mimetype = MIME::Types.type_for(file)[0]
cgi.header(mimetype.nil? ? "application/octet-stream" :
mimetype.simplified)
write File.read('file')