Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Load/save file

Questions related to using nuBuilder Forte.
Post Reply
Timo
Posts: 217
Joined: Thu Mar 15, 2018 9:26 pm
Has thanked: 1 time

Load/save file

Unread post by Timo »

I have some JavaScript libraries, files on my server, which I use in nuBuilder. My goal is to manage these external files by means of a form.
When I open a record, an external file should be loaded in a nuBuilder textarea field. When I save the record, the content of the textarea should be saved back to the JavaScript file.
general.js.png
You do not have the required permissions to view the files attached to this post.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Load/save file

Unread post by toms »

Hi,

This is how I implemented a tiny file editor.

Create a table with these fields:

file_id - type varchar(25) - primary key
file_name - type varchar(1000)
file_content - type text

Create a Browse/Edit Form with "Fast Forms". Fields field_name (input), file_content (textarea)
files_editor.PNG
In your form's Custom Code (JS):

Code: Select all

if (nuFormType() == 'edit') {

    var c = atob(fileGetContents());
// instead of atob: use this class to properly decode: https://www.coditty.com/code/utf-base64-encode-in-php-and-decode-in-javascript
    $('#file_content').val(c).change();

    $('#file_content')
        .dblclick(function() {
            nuOpenAce('Javascript', this.id);
        });

    nuHasNotBeenEdited();
}
PHP (BE):

Code: Select all

$c = base64_encode(file_get_contents("#file_name#"));

$j = "
function fileGetContents(){
   return '$c';    
}
";

nuAddJavascript($j);
PHP (AS):

Code: Select all

$filename = "#file_name#";
if ($filename != '')
{
  file_put_contents($filename,stripslashes("#file_content#"));
} 
Whenever a record is saved, the content of file_content is saved to a file that is specified in the field file_name. When a record is opened, the file contents is loaded from the file too.
Hope that helps!
You do not have the required permissions to view the files attached to this post.
Timo
Posts: 217
Joined: Thu Mar 15, 2018 9:26 pm
Has thanked: 1 time

Re: Load/save file

Unread post by Timo »

Thank you toms. I'm gonna take a look at it .
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Load/save file

Unread post by admin »

.
Post Reply