File Upload example?

File Upload example?

SeppelchenSeppelchen Posts: 69Questions: 25Answers: 1
edited August 2015 in DataTables 1.10

Hello, could anyone please provide a file upload datatable example with database connection? It would be pretty cool. Maybe a example where we could upload some pictutures (and not only one) and text fields into one row.

It would be very cool. :)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    There is an example of file upload included in the Editor 1.5 release. Upload is now integrated into the core software, so there is no need for a plug-in.

    How uploads work have been changed a bit on 1.5 to make them much easier to use. There is an upgrade document available which details the change.

    Allan

  • SeppelchenSeppelchen Posts: 69Questions: 25Answers: 1
    edited August 2015

    Hello,
    if i try your example i get a error:

    <br />
    <b>Fatal error</b>: Call to undefined method DataTables\Editor\MJoin::link() in <b>/var/***/
    /httpdocs/sub/datenpflege/DataTables/ServerSide/upload-many.php</b> on line <b>27</b><br />

    On that 2 line:

        Field::inst( 'datenpflege_lieferanten.liefnr' ),
        Field::inst( 'datenpflege_lieferanten.liefmc' )
    

    But i cant understand that lines.

    We create 2 tables:
    1 table: "datenpflege_lieferanten"

    columns:

    id
    liefnr
    liefmc
    ansprechpartner
    telefon-ansprechpartner
    e-mail-ansprechpartner
    lieferant-aktuell
    zl-oder-db
    bildrechte-nutzungsvereinbarung
    sonstige-absprachen
    image

    2 table: "datenpflege_files"

    columns:

    id
    brb-artnr
    filename
    filesize
    web_path
    system_path
    meta

    How we can fix?

    I also cant see the edit ; new and delete button and I also can not see any value but i insert all correct i think. We really need help. :(

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I sent a reply by e-mail as well, but please check that you have updated all of the files on your server to be the Editor 1.5 files. It would be worth also reading through the upgrade guide if you have not done so. As you will see from the example on the Editor site it should work.

    Allan

  • SeppelchenSeppelchen Posts: 69Questions: 25Answers: 1
    edited August 2015

    Hello, i had update editor libary.
    but will not work. I get an error. It would be pretty cool if you could help. I had submit a access email.

    Hope you will help allan.

    Because I had no idea how I can made it work. :'( :'(

    Best regards,
    Sebastian

  • SeppelchenSeppelchen Posts: 69Questions: 25Answers: 1
    edited August 2015

    Hello It seems nearly worked... but...
    If I select a file i can see: Unknown upload field name submitted

    on upload-many.php we had write:

    <?php
    
    /*
     * Example PHP implementation used for the index.html example
     */
    
    // DataTables PHP library
    include( "../php/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'datenpflege_lieferanten' )
        ->fields(
            Field::inst( 'liefnr' ),
            Field::inst( 'liefmc' ),
            Field::inst( 'ansprechpartner' )
        )
        ->join(
            Mjoin::inst( 'datenpflege_files' )
                ->link( 'datenpflege_lieferanten.id', 'datenpflege_filesuploaded.lieferanten_id' )
                ->link( 'datenpflege_files.id', 'datenpflege_filesuploaded.file_id' )
                ->fields(
                    Field::inst( 'id' )
                        ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/upload/__ID__.__EXTN__' )
                            ->db( 'datenpflege_files', 'id', array(
                                'filename'    => Upload::DB_FILE_NAME,
                                'filesize'    => Upload::DB_FILE_SIZE,
                                'web_path'    => Upload::DB_WEB_PATH,
                                'system_path' => Upload::DB_SYSTEM_PATH
                            ) )
                            ->validator( function ( $file ) {
                                return$file['size'] >= 50000 ?
                                    "Files must be smaller than 50K" :
                                    null;
                            } )
                            ->allowedExtensions( [ 'png', 'jpg', 'pdf' ], "Please upload an image" )
                        )
                )
        )
        ->process( $_POST )
        ->json();
    
    

    and on normal screen we had write:

        var editor = new $.fn.dataTable.Editor( {
            ajax: "DataTables/ServerSide/upload-many.php",
            table: "#bilddatenbank",
            fields: [ {
                    label: "Liefnr",
                    name: "liefnr"
                }, {
                    label: "Images:",
                    name: "id",
                    type: "uploadMany",
                    display: function ( fileId, counter ) {
                        return '<img src="'+table.file( 'files', fileId ).web_path+'"/>';
                    },
                    noImageText: 'No images'
                }
            ]
        } );
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    name: "id",

    For anyone else reading this, we discussed this in another thread](/forums/discussion/29453). The field name needs to refer to the place the data is stored - in this case datenpflege_files[].id.

    Allan

This discussion has been closed.