Hi Allan, hi community,
I do have a problem with FILE Upload.
Using Editor Version 2.0.5
I use File upload with a single file.
I have a table "medien" with an primary key for the fileId.
I have a sub table "v_arten" with a foreign key.
When I try to upload a file,
and press "upload"
the file is copied to the prospected file.
the dataset is written to the table "medien".
but the error "Uncaught Unknown file id xx in table yy" occurs.
if i press "save" again an then leave the pop-up dialog - the foreign key is written in the tabel "v_arten".
IF i press "cancel" it wont.
The dialog does not finish - you have to cancel it.
The "save" button changes to "processing" and will stay like this producing the error again and again.
Here is what I have in the javascript datatables definition:
var table = $('#example).DataTable( {
ajax: { url: 'dt-e.v_arten.php' } ,
columns: [
.. more columns ... only excerpt ..
{
data: "v_arten.idFMedien",
render: function ( fileId ) {
return fileId ?
'<img src="'+table.file( 'medien', fileId ).webPath+'" height="85px"/>' :
'No image';
},
defaultContent: "kein Bild",
title: "Bild"
}
(..)
],
select: true,
select: {
style: 'os'
},
buttons: [
{ extend: "create", className: "create",
editor: editor,
formButtons: [
'Speichern',
{ text: 'Abbrechen', action: function () { this.close(); } }
]
},
{ extend: "edit", className: "edit",
editor: editor ,
formButtons: [
'Speichern',
{ text: 'Abbrechen', action: function () { this.close(); } }
]
},
{
extend: "remove", className: "delete",
editor: editor,
formButtons: [
'Ja, Eintrag löschen',
{ text: 'Nein danke', action: function () { this.close(); } }
]
},
],
(the coding ist longer - i shortened it )
And here the editor definition:
var editor = new $.fn.dataTable.Editor( {
ajax: { url: 'dt-e.v_arten.php'
} ,
table: "#example",
i18n: {
create: {
button: "Neu",
title: "Neuer Eintrag",
submit: "neu"
},
edit: {
button: "Bearbeiten",
title: "Eintrag bearbeiten",
submit: "Speichern"
},
remove: {
button: "Löschen",
title: "Löschen",
submit: "Löschen",
confirm: {
_: "Sollen wirklich %d Zeilen unwiderruflich und komplett gelöscht werden?",
1: "Soll wirklich ein %d Eintrag unwiderruflich und komplett gelöscht werden?"
}
},
error: {
system: "Ein Fehler ist aufgetreten."
},
datetime: {
months: [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ],
weekdays: ['So', 'Mo', 'Di', 'Mi','Do', 'Fr', 'Sa' ],
}
},
fields: [
{
label: "Bezeichnung:",
name: "v_arten.Bezeichnung"
}
, {
label: "Beschreibung:",
name: "v_arten.Beschreibung",
type: "textarea"
}
,
{
label : "Startseite:",
name : "v_arten.AnzeigeStartseite",
type : "checkbox",
separator : "|",
unselectedValue: 0,
options : [{ label: "", value: 1 }]
}
, {
label: "Reihenfolge:",
name: "v_arten.ReihenfolgeStartseite"
}
,
{
label: "Bild: 180px x 120px ",
name: "v_arten.idFMedien",
type: "upload",
display: function ( fileId ) {
return '<img src="'+table.file( 'medien', fileId ).webPath+'"/>';
},
uploadText: "Durchsuchen ..",
clearText: "Entfernen",
dragDropText: "Datei hierher ziehen ...",
noImageText: 'Kein Bild'
}] ,
} );
And here an excerpt of the PHP:
<?php
include( $dt_lib."DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
$out = Editor::inst( $db, 'v_arten' , 'v_arten.idVArt')
->fields(
Field::inst( 'v_arten.idVArt' ) ->set(false), //ID is automatically set by the database on create
Field::inst( 'v_arten.Bezeichnung' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'Bitte eine Bezeichnung eintragen' )
) ),
Field::inst( 'v_arten.Beschreibung' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'Bitte eine Beschreibung eintragen' )
) ) ,
Field::inst( 'v_arten.AnzeigeStartseite' ) ,
Field::inst( 'v_arten.ReihenfolgeStartseite' ) ,
Field::inst( 'v_arten.Bildname' ),
Field::inst( 'v_arten.idFMedien' )
// ->setFormatter( Format::ifEmpty( null ) )
->setFormatter( 'Format::nullEmpty' )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].$_SESSION['root'].'/uploads/system/v_arten/__ID__.__NAME__' )
->db( 'medien', 'idMedien', array(
'fileName' => Upload::DB_FILE_NAME,
'fileSize' => Upload::DB_FILE_SIZE,
'webPath' => Upload::DB_WEB_PATH,
'systemPath' => Upload::DB_SYSTEM_PATH ,
'AufnahmeUser' => $_SESSION['USER'],
'AenderungsUser' => $_SESSION['USER'],
'AenderungsDatum' => date("Y-m-d H:i:s")
) )
->validator( Validate::fileSize( 500000, 'Bilder müssen kleiner sein als 500K' ) )
->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Nur Bilder können hochgladen werden (*.png, *.jpg, *.jpeg, *.gif)" ) )
->dbClean( function ( $data ) {
// Remove the file from the file system
unlink($data[0]['systemPath'] );
return true;
} )
)
,
Field::inst( 'v_arten.AenderungsDatum' )->set( Field::SET_EDIT ),
Field::inst( 'v_arten.AenderungsUser' ) ->set( Field::SET_EDIT ),
Field::inst( 'v_arten.AufnahmeUser' )->set( Field::SET_CREATE )
)
->on( 'preEdit', function ( $editor, $id, $values ) {
$editor
->field( 'v_arten.AenderungsDatum' )
->setValue( date("Y-m-d H:i:s") );
$editor
->field( 'v_arten.AenderungsUser' )
->setValue( $_SESSION['USER'] );
} )
->on( 'preCreate', function ( $editor, $values ) {
$editor
->field( 'v_arten.AufnahmeUser' )
->setValue( $_SESSION['USER'] );
} )
->debug(true)
->process( $_POST )
->json();
?>
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: