Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82226

Upload field - uncaught exception: Unknown file id

$
0
0

Hi Allan and community

We have an unusual problem with single-upload-fields.

The main table in the database is called agent_test. It is quite extensive and contains 17 single-upload-fields and 6 multi-upload-fields, among other fields for data collection.

Each single-upload-field is linked to the main table via ->leftJoin.

Each single-upload-field has its own table in the database for the purpose of saving the technical data of each file that is uploaded, like file-name, file-size, system-path and so on.

When a file has been uploaded it arrives at the destination folder on the server, the entry is made in the technical table of the corresponding upload-field and the id of the file is inserted into the main table agent_test in the corresponding column. In most cases this process works without problems and people can continue their work on the table.

However, on some rare occasions something goes wrong.

The "something going wrong" involves the disappearance of the entry made in the technical table of the corresponding upload-field. When this happens, for an unknown reason as of until now, the file id is still present in the main table agent_test but the corresponding entry in the upload-field table is gone, which leads to the main table agent_test to seize functioning and this JavaScript error is produced:

uncaught exception: Unknown file id SO-AND-SO in table SO-AND-SO

It is unclear to me why this happens. As stated, most of the time people have no problem uploading files, but on some rare occasions this situation happens.

The error can happen to any of the single-upload-fields. It is not limited to a specific one out of the 17 existing single-upload-fields.

We have not yet experienced this error with any of the multi-upload-fields.


Here are relevant portions of the code:

JavaScript:

var editor;

$(document).ready(function() {

    editor = new $.fn.dataTable.Editor( {
        ajax: "../php/test.php",
        table: "#tabAGTest",
        i18n: {
        ...
        },

        fields: [

            ...

            {
                label: "WIDVM:",
                name: "agent_test.widvm",
                type: "upload",
                display: function ( file_id ) {
                  return '<span class="file-link pdf"></span>';
                }
            },

            ...

        ]

    } );


    $('#tabAGTest').on( 'click', 'tbody td:not(:first-child,:nth-child(2),:nth-child(3),:nth-child(9))', function (e) {
          editor.bubble( this );
    } );


    var bTable = $('#tabAGTest').DataTable( {

        responsive: true,
        dom: "lBfrtip",
        ajax: "../php/test.php",

        columns: [

          { // Responsive control column
            data: null,
            defaultContent: '',
            className: 'control',
            orderable: false
          },
          { // Checkbox select column
            data: null,
            defaultContent: '',
            className: 'select-checkbox',
            orderable: false
          },

          ...

          {
            data: "agent_test.widvm",
            render: function ( file_id ) {
              return file_id ?
                '<a class="file-link pdf widvm" href="../../getfile.php?docType=widvm&fileID=' + file_id +
                '&agent=test' +
                '&ext='  + editor.file( 'u_test_widvm', file_id ).dend  +
                '&file=' + editor.file( 'u_test_widvm', file_id ).dname +'" target="_blank"></a>' : null;
            },
            defaultContent: ""
          },

          ...

        ],

        order: [ 2, 'asc' ],
        select: {
          style:    'os',
          selector: 'td.select-checkbox'
        },

        buttons: [
            ...
        ],

        language: {
            ...
        }

    } );

} );

And here is the PHP code:

// DataTables PHP library
include( "../../lib/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\Options,
  DataTables\Editor\Upload,
  DataTables\Editor\Validate,
  DataTables\Editor\ValidateOptions;


Editor::inst( $db, 'agent_test' )

    ->fields(

        ...

        Field::inst( 'agent_test.widvm' )
          ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/../private_html/upload/test/widvm/__ID__-__NAME__' )
            ->db( 'u_test_widvm', 'id', array(
              'dagent'   => 'test',
              'dend'     => Upload::DB_EXTN,
              'dgroese'  => Upload::DB_FILE_SIZE,
              'dname'    => Upload::DB_FILE_NAME,
              'sys_pfad' => Upload::DB_SYSTEM_PATH
            ) )
            ->dbClean( 'agent_test.widvm', function ( $data ) {
              for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
                if ( is_file( $data[$i]['sys_pfad'] ) )
                  unlink( $data[$i]['sys_pfad'] );
              }

              return true;
            } )

            ->validator( function ( $file ) {
              if ( strlen($file['name']) > 50 ) {
                return "File name should not contain more than 50 characters.";
              }
              return null;
            } )
            ->validator( function ( $file ) {
              if ( $file['size'] >= 1000000 ) {
                return "File size should be smaller than 1MB.";
              }
              return null;
            } )
            ->validator( Validate::fileExtensions(
              array( 'pdf' ),
                'Only PDF files allowed.'
            ) )
          )

          ->setFormatter( Format::ifEmpty( null ) ),

        ...

    )

    ...

    ->leftJoin( 'u_test_widvm',    'u_test_widvm.id',    '=', 'agent_test.widvm' )

    ...

    ->process( $_POST )
    ->json();

Does anyone have an idea what may be causing this problem?


Viewing all articles
Browse latest Browse all 82226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>