0

I has a requirement like when user clicks on a download button instead of showing the content in browser, i want to save it to the localdisk(perticular location) of the user desktop. Is it possible to do?? If yes,Please help me with possibilities..

Thanks in advance

RAVITEJA SATYAVADA
  • 2,453
  • 21
  • 51
  • 85

2 Answers2

1

No a website can't decide where it can save something. Everything goes to download folder by default. You have to be using some sort of plugin with permissions or make like browser addon/extension.

If you want to prompt download then you could set send headers in php:

Content-Disposition: attachment; filename="fname.ext" and

Content-Type: application/force-download

Or you could set attribute download to link in html

<a href="file.abc" download>Click Me</a>

Utility of HTTP header "Content-Type: application/force-download" for mobile?

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

http://www.php.net/manual/en/function.header.php

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes

Community
  • 1
  • 1
Muhammad Umer
  • 14,722
  • 14
  • 69
  • 139
1

You shall just point the file name like this to download.

But you cannot decide the path by your code.

<a href="www.tutorialspoint.com/php/php_tutorial.pdf‎">Download the File</a>

Note : Do not try this in jsfiddle or in codepen because they will rename the link with their custom so that the file will be displayed within their output. So, try it in your web server or in your localhost.

Sulthan Allaudeen
  • 10,822
  • 12
  • 44
  • 59