user1559811
user1559811

Reputation: 449

function to empty a files content

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

Answers (3)

Arpit
Arpit

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

doniyor
doniyor

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

James Hill
James Hill

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

Related Questions