Page 1 of 1

Best solution to attach images to a record

Posted: Fri Aug 03, 2018 9:15 pm
by deckoff
Hello
I am doing a simple dental database application, but I need some images (x-rays)attached to the database for each patient.
What would be the best way to store that - I need the file to be uploaded form the patients form, and be shown when needed. What would be the best solution to do this?

Re: Best solution to attach images to a record

Posted: Mon Aug 06, 2018 11:02 am
by toms
Hi,

If several files per patient have to be stored, a Subform (Type Grid) with an "Upload File" object might be suitable.

https://wiki.nubuilder.cloud/ ... .php/Files

Re: Best solution to attach images to a record

Posted: Wed Aug 08, 2018 7:42 am
by deckoff
Hey, thank you
Since I need to store the x rays in as good quality as possible, 300 kb doesnt cut it. What I am working on is a simple html element added to the xray form

Code: Select all

<form id="data" method="post" enctype="multipart/form-data">
    <!--<input type="text" name="first" value="Bob" />-->
    <!--<input type="text" name="middle" value="James" />-->
    <input type="hidden" name="last" value="" id="xRayName" />
    <input name="image" type="file" />
</form>
jquery, triggered by the save button:

Code: Select all

$( "#nuSaveButton" ).click(function() {
    // e.preventDefault();
    

    var xRayName = $("#pro_name").val();
    $("#xRayName").val(xRayName);
    
    console.log(xRayName);  
    
    
    var formData = new FormData(data);


    console.log(formData)
    $.ajax({
        url:"upload.php",
        type: 'POST',
        data: formData,
        success: function (data) {
            console.log(data)
        },
        cache: false,
        contentType: false,
        processData: false
    });
});
Upon clicking save, nuBuilder will save the file on the server, and create entry in the nuBuilder database, that stores the name of the file, and the customer it belongs to.
I plan add some simple query, that will open the xray in broweser window upon clicking the subform entry of the name
A few things still need to be ironed out.
any suggestions welcome

Re: Best solution to attach images to a record

Posted: Wed Aug 08, 2018 8:32 am
by toms
Hi,

This form thread might also be useful. It's about uploading files to the server & downloading them.

Re: Best solution to attach images to a record

Posted: Wed Aug 08, 2018 6:28 pm
by toms
deckoff wrote: any suggestions welcome
I wouldn't do it in this way (will not be triggered if the save shortcut is pressed)

Code: Select all

$( "#nuSaveButton" ).click(function() {
...
});
Instead, I'd add a nuBeforeSave() event handler:

Code: Select all

function nuBeforeSave() {

    if (nuFORM.edited === true) {
         Run your Code here....
    }

    return true;
}

Re: Best solution to attach images to a record

Posted: Fri Aug 10, 2018 9:34 am
by deckoff
Hmmm, I also have the problem that values added with

Code: Select all

$( "#pro_code" ).val("test")
where pro_code is and input id, value get deleted, and the filed is empty. If I add it manually, it stays.
Could that help?

Re: Best solution to attach images to a record

Posted: Fri Aug 10, 2018 9:55 am
by toms
Hi,

You need to invoke .change() otherwise the value will not be saved to the DB.

Code: Select all

( "#pro_code" ).val("test").change();

Re: Best solution to attach images to a record

Posted: Fri Aug 10, 2018 4:01 pm
by deckoff
Thanx, worked like charm!!!

Re: Best solution to attach images to a record

Posted: Fri Aug 10, 2018 8:01 pm
by admin
.