Reputation: 3
Here is my problem, I would like to upload a file from a local path but i can't change input file value because it is impossible
The classical code of simple file upload :
HTML-code:
<input id="file" type="file" />
<progress id="progress"></progress>
JavaScript-code:
var fileInput = document.querySelector('#file'),
progress = document.querySelector('#progress');
fileInput.addEventListener('change', function() {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'upload.html');
xhr.upload.addEventListener('progress', function(e) {
progress.value = e.loaded;
progress.max = e.total;
}, false);
xhr.addEventListener('load', function() {
alert('Upload terminé !');
}, false);
var form = new FormData();
form.append('file', fileInput.files[0]);
xhr.send(form);
}, false);
How can we change it?
Upvotes: 0
Views: 1241
Reputation: 833
You can't do it with pure JS. Modern browsers prevent you from direct work with the user's filesystem due to obvious insecurity. However, you can try to do it using Flash, ActiveX, Silverlight and so on.
Upvotes: 2