file upload to server

Questions related to using nuBuilder Forte.

file upload to server

Postby johan » Mon Feb 25, 2019 11:11 pm

Hi, we are trying to make file uploads work as suggested on the forum here:
viewtopic.php?f=19&t=9475&hilit=upload&start=10

But, we would like to allow multiple files to be added to the same record, so we created a table that will link recordid and uploaded file (file uploads get a unique name).
The problem we are having is that the name of the file is not available in the after-save handlers.

Where should we insert the code to write the record to the files table we created?
Johan
johan
 
Posts: 268
Joined: Sun Feb 27, 2011 7:46 pm
Location: Belgium

Re: file upload to server

Postby kev1n » Mon Feb 25, 2019 11:26 pm

In Javascript, use an array to store the file names:

Code: Select all
// Create an array
var files = new Array;

// Push the file names to the array
files.push(first_file);
files.push(second_file);
// ....

// Convert the array to a JSON string and set a hash cookie:
var j = JSON.stringify(files);
nuSetProperty('myfiles',j);


In PHP, use json_decode() to decode the JSON string an you want to loop through the array, use a foreach loop.

Code: Select all
$f = json_decode("#myfiles#")
kev1n
 
Posts: 185
Joined: Mon Oct 15, 2018 2:13 am

Re: file upload to server

Postby johan » Wed Feb 27, 2019 1:23 am

Kevin
Thanks for your reply.
Where should we inject that java code in the linked solution? I assume it needs to go somewhere in the code that calls process_file.php?

Johan
johan
 
Posts: 268
Joined: Sun Feb 27, 2011 7:46 pm
Location: Belgium

Re: file upload to server

Postby kev1n » Wed Feb 27, 2019 5:48 pm

johan wrote:Where should we inject that java code in the linked solution? I assume it needs to go somewhere in the code that calls process_file.php?


Within the ajax success callback (added lines flagged with *ADD* )

ajaxsuccess.png
ajaxsuccess.png (22.67 KiB) Viewed 488 times
kev1n
 
Posts: 185
Joined: Mon Oct 15, 2018 2:13 am

Re: file upload to server

Postby johan » Sat Mar 02, 2019 12:26 am

Kevin
I changed the HTML code to that in the image, but now the upload fails, the error in the console is:
ReferenceError: f is not defined

What did I miss?
johan
 
Posts: 268
Joined: Sun Feb 27, 2011 7:46 pm
Location: Belgium

Re: file upload to server

Postby kev1n » Sat Mar 02, 2019 1:01 am

If you click on this "VM"-link, you'll see the line the causes the error.

err.png
err.png (5.18 KiB) Viewed 470 times
kev1n
 
Posts: 185
Joined: Mon Oct 15, 2018 2:13 am

Re: file upload to server

Postby johan » Sat Mar 02, 2019 2:38 am

Kevin
My error points to
function nuLoginRequest(u, p){
$.ajax({
async : true,
dataType : "json",
url : "nuapi.php",
method : "POST",
data : {nuSTATE :
{call_type : 'login',
username : arguments.length 0 ? $('#nuusername').val() : u,
password : arguments.length 0 ? $('#nupassword').val() : p,
login_form_id : nuLoginF,
login_record_id : nuLoginR}
},
dataType : "json",


I don't see any f
johan
 
Posts: 268
Joined: Sun Feb 27, 2011 7:46 pm
Location: Belgium

Re: file upload to server

Postby kev1n » Sat Mar 02, 2019 3:36 am

I don't know what your code looks like and where you added it. Without that information it's next to impossible to know what causes this error.
kev1n
 
Posts: 185
Joined: Mon Oct 15, 2018 2:13 am

Re: file upload to server

Postby johan » Mon Mar 04, 2019 5:19 pm

Kevin
We find our error in the object (Html) part.
Now we can try the rest.
Thanks
Johan
johan
 
Posts: 268
Joined: Sun Feb 27, 2011 7:46 pm
Location: Belgium

Re: file upload to server

Postby johan » Mon Mar 11, 2019 6:57 pm

Kevin
"We want to write data to another table using the after save handler where we have the recordid available. How would we do that? Specificly, looking at how to use the SQL connection Nubuilder already has
johan
 
Posts: 268
Joined: Sun Feb 27, 2011 7:46 pm
Location: Belgium

Next

Return to General