Home > Mobile >  How to send HTML form data basically file <input type="file" name="file" valu
How to send HTML form data basically file <input type="file" name="file" valu

Time:12-08

We are working on a project where we are using form tag to access a file from our system and then download it back to our system basically on the desktop using html .

I am expecting the file to be saved on the desktop

CodePudding user response:

It is not possible to send an HTML form with a file input to the desktop using only HTML. HTML is a markup language used to structure and display content on the web, and it does not have the ability to save files to the user's desktop or other local storage.

To save a file from an HTML form to the user's desktop, you will need to use a combination of HTML, JavaScript, and a server-side language such as PHP. Here is a general overview of the process:

  1. In the HTML form, use the input element with the type="file" attribute to allow the user to select a file from their device.

  2. Use JavaScript to handle the form submission and get the selected file.

  3. Use JavaScript to send the file to the server using an AJAX request or a form submission with the enctype="multipart/form-data" attribute.

  4. On the server, use the server-side language (e.g. PHP) to receive the file and save it to the desired location on the server.

  5. Use JavaScript to download the saved file from the server to the user's desktop.

Overall, this is a complex process that requires a good understanding of web development technologies. It is not possible to accomplish this task using only HTML. That is, if I understood your question correctly.

CodePudding user response:

You need javascript to do it. You can try this code :

<input type="input" id="inputFile" />
<a id="downloadLink">Download the file</a>

<script>

const fileInput = document.getElementById("inputFile")
const downloadLink = document.getElementById("downloadLink")

fileInput.addEventListener("change", () => {
    if (!fileInput.files.length) return;
    const urlObj = URL.createObjectURL(fileInput.files[0])
    downloadLink.href = urlObj
})

</script>
  • Related