Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert image deleting from file...

Replytotopic

image deleting from file

Posted in Forums : Ask a Rails expert

 
Profile

Authority 25
Posting Rating 2
Sign in to rate this post

can any one help deleting image(which is uploaded to public/profile image folder)rom file. mohd anas

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

File.delete(filename, ...) is the function you need.

Try File.delete(”#{RAILS_ROOT}/public/profile image folder/#{filename}”)

 
Rj-blogshot

Authority 75
Posting Rating 95
Sign in to rate this post

Another trick I am very partial to in Ruby is the ability to run bash commands dynamically. So you could also use backticks like so:

`rm #{RAILS_ROOT}/public/profile image folder/#{filename}`

Of course this kind of thing will break on Windows, but sorry, Windows isn’t a proper development or deployment platform, we have been saying it since people wanted to compile and host MUDs on their Windows boxes.

 
Working_with_rails

Authority 12
Posting Rating 91
Sign in to rate this post

James, try to use backticks with filename = ’ || rm -rf /’ ;)

to be platform independent use File.delete and File.join:
File.delete( File.join(RAILS_ROOT, ‘public’, ‘profile_image_folder’, filename) )

Replytotopic

Other Recent Topics

Ask a Rails expert : First post, requesting sage perspective

Ask a Rails expert : How to use mephisto

Ask a Rails expert : How to use mephisto

Ask a Rails expert : will_paginate customization problem

Ask a Rails expert : BackgroundRB still wants 'development' environment...?

Ask a Rails expert : activescaffold, sql exception

Ask a Rails expert : Passing non-english chars in query string

Ask a Rails expert : Rails and 2D barcodes

Ask a Rails expert : apache giving proxy error

Ask a Rails expert : Custom Responses w/ 'extra' information...?

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel