Page 1 of 3
file upload to an specific url/address
Posted: Sun Apr 22, 2018 4:48 am
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.
Re: file upload to an specific url/address
Posted: Sun Apr 22, 2018 6:47 am
by admin
omid020,
That's not what nuBuilder is for so you'll need to use a third party product like Dropbox.
Steven
Re: file upload to an specific url/address
Posted: Sun Apr 22, 2018 7:59 am
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.
Re: file upload to an specific url/address
Posted: Sun Apr 22, 2018 8:50 pm
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.
Re: file upload to an specific url/address
Posted: Sun Apr 22, 2018 9:03 pm
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.
Re: file upload to an specific url/address
Posted: Sun Apr 22, 2018 9:54 pm
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)
Re: file upload to an specific url/address
Posted: Mon Apr 23, 2018 8:06 am
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);
}
});
Re: file upload to an specific url/address
Posted: Mon Apr 23, 2018 4:38 pm
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!
Re: file upload to an specific url/address
Posted: Mon Apr 23, 2018 7:03 pm
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
Re: file upload to an specific url/address
Posted: Mon Apr 23, 2018 8:06 pm
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();
...
}