Reputation: 449
I want to make a function that empties a files content if a button is clicked when the value is not etmpy, is this at all possible?
function file_empty() {
var file = document.getElementById('file');
if(file.value !=="") {
// empty the file
return true;
}
}
<input name="uploaded" type="file" id="file" />
<input type="submit" value="empty-if-full" onclick="return file_empty();" />
Upvotes: 2
Views: 103
Reputation: 12797
As the @james sir says its not possible with javascript but you can lookat html5 filereader.
Here you can check How to open a local disk file with Javascript?
Upvotes: 1
Reputation: 37876
file system is something which cannot be reached by frontend-scripts. js is one of them. i was also struggling to open and write into file by js, it is also hardly possible.. so you should stick to something like php, python, java etc...
Upvotes: 1
Reputation: 61802
No, this is not possible. JavaScript has zero access to the file system.
A server-side language (C#, VB, PHP, ColdFusion, Ruby, etc.) is required to do what you want.
Upvotes: 5