Welcome to the nuBuilder Forums!

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

file upload to an specific url/address

Questions related to using nuBuilder Forte.
omid020
Posts: 21
Joined: Mon Apr 16, 2018 9:12 am

file upload to an specific url/address

Unread post by omid020 »

It seems input:File uploads files directly into database. Is there any solution for uploading files directly into an specific folder of url/address?
I have many large files and can't rely to database to hold them.

Thanks in advance.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: file upload to an specific url/address

Unread post by admin »

omid020,

That's not what nuBuilder is for so you'll need to use a third party product like Dropbox.

Steven
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: file upload to an specific url/address

Unread post by toms »

Hi,

This can be done with ajax and php and works just fine.

I'm using this code with slight modifications: https://gist.github.com/matteomattei/e2 ... 73b2da2921

Create a object of type HTML and add the code from index.html. process_files.php has to be saved on your server.

Let me know if you need more details/instructions.
omid020
Posts: 21
Joined: Mon Apr 16, 2018 9:12 am

Re: file upload to an specific url/address

Unread post by omid020 »

Hi,

Thanks for your advise. I created html object and moved process_files.php to nuBuilder main root folder, also I created uploads folder inside nuBuilder main root folder but it seems uploading operation failed; After choosing PDF file "Uploading" message loads (nothing more) and after saving form no file adds to upload folder.
Also I need to have a column (in browsing mode and within same table form) to contain a hyperlink to download the uploaded file. Could you please guide to have it?

Thanks in advance.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: file upload to an specific url/address

Unread post by toms »

Check the console output if you see any errors. In my case, I had to change the paths to process_files.php to /html/nuBuilder4/process_files.php (it's probably different for you)

The ajax success function returns the file names (In my case just 1 file name since I disallow multiple files)
This saves the filename to a nuBuilder field:

CODE: SELECT ALL

Code: Select all

success: function (res) {
         ....
   if(result.res === true){
      ...
$('#myfilename').val(result.data[0]).change(); 
...
}
Then you can add the full path location to the filename and display it.
omid020
Posts: 21
Joined: Mon Apr 16, 2018 9:12 am

Re: file upload to an specific url/address

Unread post by omid020 »

I changed path of php file to /public_html/nuBuilder4/process_files.php or public_html/nuBuilder4/process_files.php but both didn't work.
Also console returns nothing. (please see the attachment)
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: file upload to an specific url/address

Unread post by toms »

Did you add the path to both occurrences of process_files.php?

1st occurence:

Code: Select all

  $.ajax({
                            url: "/process_files.php",  

2nd occurence:

Code: Select all

 <form method="post" enctype="multipart/form-data"  action="/process_files.php">
You can also add and error handler to give you more details why the upload fails.

Code: Select all

 $.ajax({
     // ...
     success: function (res) {
         // ....
     },
     error: function(jqXHR, textStatus, errorThrown) {
         alert('An error occurred... Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information!');
         console.log('jqXHR:');
         console.log(jqXHR);
         console.log('textStatus:');
         console.log(textStatus);
         console.log('errorThrown:');
         console.log(errorThrown);
     }
 });
omid020
Posts: 21
Joined: Mon Apr 16, 2018 9:12 am

Re: file upload to an specific url/address

Unread post by omid020 »

toms wrote:Did you add the path to both occurrences of process_files.php?

1st occurence:

Code: Select all

  $.ajax({
                            url: "/process_files.php",  



2nd occurence:

Code: Select all

 <form method="post" enctype="multipart/form-data"  action="/process_files.php">
Yes I had edited path for both items.
toms wrote: You can also add and error handler to give you more details why the upload fails.

Code: Select all

 $.ajax({
     // ...
     success: function (res) {
         // ....
     },
     error: function(jqXHR, textStatus, errorThrown) {
         alert('An error occurred... Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information!');
         console.log('jqXHR:');
         console.log(jqXHR);
         console.log('textStatus:');
         console.log(textStatus);
         console.log('errorThrown:');
         console.log(errorThrown);
     }
 });
I added above code into html code but still no errors apperars!
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: file upload to an specific url/address

Unread post by toms »

Sorry, I have no idea why it's not working for you. In any case, you can also test the upload independently of nuBuilder.

Debugging Javascript might help you track down the issue as well:
https://developer.mozilla.org/en-US/doc ... JavaScript
omid020
Posts: 21
Joined: Mon Apr 16, 2018 9:12 am

Re: file upload to an specific url/address

Unread post by omid020 »

Finally worked! Just removed /public_html from the path and it works like a charm!

which type of field should I add to table of database to have a link (for example a link with "download" phrase) of file for every corresponding input via your mentioned code?

Code: Select all

success: function (res) {
         ....
   if(result.res === true){
      ...
$('#myfilename').val(result.data[0]).change();
...
}
Locked