validation for file

Discussion in 'Ruby' started by Sunny Bogawat, May 9, 2008.

  1. 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 !
    --
    Posted via http://www.ruby-forum.com/.
     
    Sunny Bogawat, May 9, 2008
    #1
    1. Advertising

  2. Sunny Bogawat

    7stud -- Guest

    Sunny Bogawat wrote:
    > 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
    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, May 9, 2008
    #2
    1. Advertising

  3. On 09.05.2008 08:38, 7stud -- wrote:
    > Sunny Bogawat wrote:
    >> 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
     
    Robert Klemme, May 10, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,712
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,540
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    440
    Tommy
    Nov 29, 2003
  4. Matt
    Replies:
    14
    Views:
    4,172
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  5. Lucas Tam
    Replies:
    2
    Views:
    1,139
    Lucas Tam
    Feb 26, 2004
Loading...

Share This Page