I want to grab files put into the form into a folder in the same directory all i have is the form and a the javascript for the file to be able to get selected
<form>
<div id="filejs" >
<label >
<input type="file" name="stuff" />
<span >
<span >
<i ></i>
</span>
<span > </span>
</span>
<span > Upload file </span>
<input type="submit" value="Submit input" />
</label>
</div>
</form>
<script>
const fileInput = document.querySelector("#filejs input[type=file]");
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
const fileName = document.querySelector("#filejs .file-name");
fileName.textContent = fileInput.files[0].name;
}
};
</script>
CodePudding user response:
You can not get uploaded files from a form with client-side Javascript. You will require any backend technology for this job. You can use node.js as it is an asynchronous event-driven JavaScript runtime environment. There are many free packages available that can handle form files and form data like multer, formidable, form-data etc.
Also, you can check out the PHP form handling method here.
