Deleting files while using DTE File upload (many)
Deleting files while using DTE File upload (many)
Hi guys,
could anyone of you provide me with backend editor code for deleting files, while using File upload (many)?
I tried code from https://editor.datatables.net/manual/php/upload#Deletion-of-orphaned-files , but it deletes all my files, so I suppose that works only for File upload (one).
Remark: I use it already with File upload (one) and there is no problem.
My Editor version: 1.5.3 (DataTables 1.10.10).
Important part of code:
// This below does not work with File upload (many).
->dbClean( function ( $data ) {
// Remove the files from the file system
for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
unlink( $data[$i]['system_path'] );
}
// Have Editor remove the rows from the database
return true;
} )
All relevant code:
// Build our Editor instance and process the data coming from _POST
Editor::inst($db, 'table')
->fields( ... )
->join(
Mjoin::inst( 'files' )
->link( ... )
->link( ... )
->fields(
Field::inst( 'id' )
->upload( Upload::inst( '/public/upload/__ID__.__EXTN__' )
->db( ... )
// This below does not work with File upload (many).
->dbClean( function ( $data ) {
// Remove the files from the file system
for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
unlink( $data[$i]['system_path'] );
}
// Have Editor remove the rows from the database
return true;
} )
->validator( ... )
)
)
)
->where( ... )
->process($_POST)
->json();
Remark: I had troubles uploading multiple files, but replacing $.ajax( $.extend( ajax, {
with $.ajax( $.extend( {}, ajax, {
helped me (from error on image upload- Cannot read property 'id' of undefined).
Replies
I think that's a bug I'm afraid. The database clean isn't running on the many join. Let me look into that and get back to you.
Allan
An update on this issue is available in this thread should anyone happen to find this.
Allan