Page 1 of 2

file upload to server

PostPosted: Mon Feb 25, 2019 11:11 pm
by johan
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

Re: file upload to server

PostPosted: Mon Feb 25, 2019 11:26 pm
by kev1n
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#")

Re: file upload to server

PostPosted: Wed Feb 27, 2019 1:23 am
by johan
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

Re: file upload to server

PostPosted: Wed Feb 27, 2019 5:48 pm
by kev1n
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 808 times

Re: file upload to server

PostPosted: Sat Mar 02, 2019 12:26 am
by johan
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?

Re: file upload to server

PostPosted: Sat Mar 02, 2019 1:01 am
by kev1n
If you click on this "VM"-link, you'll see the line the causes the error.

err.png
err.png (5.18 KiB) Viewed 790 times

Re: file upload to server

PostPosted: Sat Mar 02, 2019 2:38 am
by johan
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

Re: file upload to server

PostPosted: Sat Mar 02, 2019 3:36 am
by kev1n
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.

Re: file upload to server

PostPosted: Mon Mar 04, 2019 5:19 pm
by johan
Kevin
We find our error in the object (Html) part.
Now we can try the rest.
Thanks
Johan

Re: file upload to server

PostPosted: Mon Mar 11, 2019 6:57 pm
by johan
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