Problem realted to upload

I want to upload a file.
And what I am confused about is…should I upload it using a separate
table or just as another file in the form.
If as a separate table then I am not able to save it on the system/
Or/ If not that, then how can i check for the extensions?
Do reply.
Thanks.

John,
Have you looked at the file_column plugin(
http://www.kanthak.net/opensource/file_column/)? What do you mean by
using
a seperate table? Are you trying to stick the file in the database or
by
table do you mean the reference to the file location? As for the file
extension’s I’m not exactly sure, the ruby File.ftype returns the type
of
the file which may be useful for you. Otherwise you might be stuck
doing
some regex.

Rob

John,

Here’s a regex that will strip out the extension of a filename. What it
actually does is returns everything after a ‘.’ is first encountered in
the
string, so: “filename.doc” would return “doc”.

file_name = “my_file.ext”

regex = Regexp.new(’.(.*)$’)
match_data = regex.match(file_name)
file_extension = match_data[1]

Hope that helps.

Rob

Rob,
I tried using validates_format_of…
But didn’t not get the desired results, what i actually did was…

validates_format_of :user_file,
:with => %r{.(doc|pdf)$}i,
:message => “please”
But gives me

undefined method `user_file’ for #User:0xb768a07c

If you could help. I am new to Ruby on Rails, so I might be sounding
silly too but hope you understand and would help.

Thanks.

Rob M. wrote:

John,

Here’s a regex that will strip out the extension of a filename. What it
actually does is returns everything after a ‘.’ is first encountered in
the
string, so: “filename.doc” would return “doc”.

file_name = “my_file.ext”

regex = Regexp.new(’.(.*)$’)
match_data = regex.match(file_name)
file_extension = match_data[1]

Hope that helps.

Rob

Thankyou Rob.
I’ll try to be more explanatory.
Actually, I want to upload a file entered by the user using simple
“input file” option in the _form.rhtml code. And after that I want to
check for the right extensions. That is it needs to just upload the doc
file.
Doing this I am stuck up with the extension checking. Though its saving
everything in the /public/ file very comfortably.
Hoping to hear more.
Thanks once again.

Rob M. wrote:

John,
Have you looked at the file_column plugin(
http://www.kanthak.net/opensource/file_column/)? What do you mean by
using
a seperate table? Are you trying to stick the file in the database or
by
table do you mean the reference to the file location? As for the file
extension’s I’m not exactly sure, the ruby File.ftype returns the type
of
the file which may be useful for you. Otherwise you might be stuck
doing
some regex.

Rob