validation for file

S

Sunny Bogawat

i am developing one application in which user uploaded one csv template
to my system(file). but we have to take care that user should uploaded
csv file only if he trying to upload another file we have to restrict
it.
how to check for extention in ruby on rails ya there is another solution
for it?
i am doing something like
file_name =params[:group_member_information].original_filename
begin
f = File.new("#{path}/#{file_name}", "wb")
str = params[:group_member_information].read
f.write str
f.close

please reply !
 
7

7stud --

Sunny said:
i am developing one application in which user uploaded one csv template
to my system(file). but we have to take care that user should uploaded
.csv file only if he trying to upload another file we have to restrict
it.
how to check for extention in ruby on rails

Does this forum say "ruby on rails" anywhere? Or is it your
understanding that any forum that contains the words "ruby" or "rails"
could not possibly be related to precious gems or trains.

In the Ruby programming language, which is what this forum is about, you
could do something like this:

fnames = ["somefile.csv", "anotherfile.jpg"]

fnames.each do |fname|
pieces = fname.split(".")

if pieces[-1] != "csv"
print "bad file: ", fname
puts
end

end
 
R

Robert Klemme

Sunny said:
i am developing one application in which user uploaded one csv template
to my system(file). but we have to take care that user should uploaded
.csv file only if he trying to upload another file we have to restrict
it.
how to check for extention in ruby on rails

In the Ruby programming language, which is what this forum is about, you
could do something like this:

fnames = ["somefile.csv", "anotherfile.jpg"]

fnames.each do |fname|
pieces = fname.split(".")

if pieces[-1] != "csv"
print "bad file: ", fname
puts
end

end

This is a rather weak check as it only tests the file name. Note, that
you can do this more easily:

ok = /\.csv$/i =~ file_name

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top