Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy a file in Ruby on Rails

I would like to copy a file from my computer to another specified path. The file has to be chosen by the user with a file_field and the destination is already hard-coded. How can I do that ? Thank you.

like image 970
TW147 Avatar asked Jul 12 '11 17:07

TW147


Video Answer


1 Answers

I'd use FileUtils::cp, but beware of path mangling via ../../<file>. For that, you can use expand_path and then check if the resulting path begin matches your jail.

like image 59
Reactormonk Avatar answered Oct 18 '22 19:10

Reactormonk