is there anyway to specify which folder you want the file to be downloaded by a download link?
let say i have a word document to be downloaded and i want it to be downloaded in users mydocuments folder by default. is there any way to specify that?

Dani AI

Generated

Short answer: no — a website cannot force a file to be saved into a specific folder like the user’s My Documents. and were right: browsers only let sites suggest a filename (or ask the user to save), not pick an arbitrary filesystem path. Different OSes and user settings mean “My Documents” isn’t a reliable target anyway. (developer.mozilla.org)

What you can do from the server/page:

  • Suggest a filename with the HTTP header Content-Disposition: attachment; filename="report.docx".
  • Use the HTML5 download attribute on an <a> to propose a filename (works best for same-origin or blob/data URLs).
    These only affect the suggested filename; browsers will strip or change path characters and decide where to save. Example header:
Content-Disposition: attachment; filename="report.docx"

(developer.mozilla.org)

If true folder control is required, the options all need explicit user consent:

  • File System Access API (web apps): opens a save dialog so the user picks the folder; sites cannot silently write to arbitrary folders. This requires HTTPS, a user gesture, and browser support may vary.
  • Browser extensions (with the downloads permission): can specify a path relative to the browser’s downloads directory, but must be installed and granted permission by the user. (developer.mozilla.org)

Practical next steps: have the server set a friendly filename, tell users how to change their browser’s default downloads folder or enable “ask where to save each file,” or provide a small native app/extension for tightly controlled workflows. Those approaches respect browser security and will work consistently across different user setups. (developer.mozilla.org)

Recommended Answers

All 5 Replies

Member Avatar for Member #119018

I don't believe it is possible. Security setups don't allow website to control that kind of information. Especially considering that some users won't have a My Documents folder! Then where the file go?

i like your avatar :)
yeah i also thought it was not possible...

No because not all filesystems are the same, and there is no guarantee the user data will be in a standard, static, or even local location anyway.

Member Avatar for Member #360561

No because not all filesystems are the same, and there is no guarantee the user data will be in a standard, static, or even local location anyway.

Each user specifies this in the browser.

obviously, but there is no way for a remote site to influence this using plain html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.