File save limitations

I know that for security reasons there are limitations on writing files but wonder if there any way round this.
My objective is to read a file, add a line to it and then save it, with the same name.
I’m using saveTable and it writes ok to my Download directory but it saves it as
filename(1) then next time as filename(2) etc.
Is there any way to force an overwrite rather than generate a new file each time?

Hi,

there is no possibility to overwrite file from a web client because of limitations, but you can setup a local server with express (for example), and then use the fs module of Node.js to overwrite files.
Depends on what you plan to do

What I plan to do is ‘read a file, add a line to it and then save it’.
I don’t know anything about Node.js but yes, doing stuff server-side could be an answer. I’m more familiar with php so maybe I could

  • rename myfile on server using PHP
  • then let P5js saveTable as myfile
    I have my own web server so can put my PHP there.
    I know how to invoke php scripts from within html, but is it possible to invoke PHP from within P5js?

You can send a post request in JS pointing to the php file which will save your file (using the axios lib or the fetch API). You’ll need to pass in arguments of your request your file.

Thanks for reply. I’ll look at axios lib but for now I’ve got it working by doing an Ajax POST to my server side php script, which appends the new lines. So PHP is doing the file updates now not P5js.