hi all

i am trying to allow the user to select the folder to store the downloading file using javascript i didnt found input attribute for download like file i try with downloadify.js but its not work their is another way i can do it

Dani AI

Generated

Short answer: a normal web page cannot automatically write a file into an arbitrary folder on a user’s disk or discover the folder the user uploaded from. Modern browsers intentionally hide real client paths (file inputs show a fake path like C:\fakepath\) and disallow silent writes for security; this is why and were correct. (developer.mozilla.org)

If the goal is "open an editor, modify the original file, then save back" the current in-browser option is the File System Access API (methods such as showOpenFilePicker, showSaveFilePicker, showDirectoryPicker). That API lets a site read/write files or directories only after the user explicitly picks them and grants permission. It requires HTTPS, a user gesture, and feature detection; support is strongest in Chromium-based browsers, so progressive enhancement and fallbacks are necessary. (developer.mozilla.org)

A minimal client-side pattern (where supported):

async function saveToDirectory(fileName, contents) {
  const dir = await window.showDirectoryPicker();        // user picks folder
  const fh = await dir.getFileHandle(fileName, {create: true});
  const writable = await fh.createWritable();
  await writable.write(contents);
  await writable.close();
}

This requires explicit user selection and permission handling. (developer.mozilla.org)

If the API isn’t available, fall back to server-side processing (upload → server edit → return download) or offer a native/extension solution. An <a download> or Content-Disposition can suggest a filename but cannot control the save folder. A Chrome extension (downloads API) or a desktop app (Electron) can provide stronger file-system access; the library browser-fs-access is a good ponyfill that transparently falls back when the File System Access API is absent. Practical choice depends on required UX and target browsers. (developer.mozilla.org)

Cautions: persist file/directory handles only with explicit user consent (IndexedDB), handle permission revocation and concurrent writes, and always feature-detect and provide a clear fallback path. (web.dev)

Recommended Answers

All 5 Replies

Javascript cannot specify download locations of any file. That would be a serious security problem.

In most cases, I don't see what the problem is letting the user pick themselves where to save downloaded files? What exactly are you trying to do this for? Unless you're doing something malicious I can't see why it would cause a problem.

i am creating editor which automatic add more text to exits file
once user upload the file its go two or more task later it has to store in same folder has user upload from

Member Avatar for Member #120589

This can't be done - thankfully.

for the security reason or any other reason

Folder selection is controlled by the user anyway, by the default handlers in every browser and every OS, there is nothing to be done by you.

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.