Web Development

Creating a page where you can download files, is a normal task when creating applications. Clients sometimes need places where a PDF file or CSV file can be downloaded by users. Normally we write a bunch of codes to force the browser to download the file.

In Ruby on Rails, you would write something like this:

def download
  send_file(File.join(File.join(Rails.root, "public", "images"), "image.jpg"))
end

In CodeIgniter, you would write something like this:

public function download() {
    force_download('/path/to/image.jpg', NULL);
}

This would force download the image.jpg from your server.

HTML5 has a solution so that we don’t need to write something that tedious. The download attribute.

<a href="http://gistpages.com/assets/logo.png" download>Download</a>

Demo

Make sure you checkout the demo at https://jsfiddle.net/teejay/bq92f74v/

Download attribute screenshot