Upload many combined with child table

Upload many combined with child table

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0
edited January 2018 in Editor

Hello everyone,

I tried to combine the upload many example (https://editor.datatables.net/examples/advanced/upload-many.html) with child table example (https://datatables.net/blog/2016-03-25) to upload files only for the child entries, but I always get the error message "A server error occurred while uploading the file".

I guess the error occurs due the php server script.

I set up an extra SQL-Table like this (with one manually created entry):

CREATE TABLE `files` (
  `id` int(8) NOT NULL auto_increment,
  `user_id` varchar(128) NOT NULL,
  `file_id` varchar(128) NOT NULL,
  `filename` varchar(128) NOT NULL,
  `filesize` varchar(128) NOT NULL,
  `web_path` varchar(256) NOT NULL,
  `system_path` varchar(256) NOT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

INSERT INTO `files` (`id`, `user_id`, `file_id`, `filename`, `filesize`, `web_path`, `system_path`) VALUES 
(1, '58', '1', 'tset.pdf', '4232424', 'http://127.0.0.1/upload/', '/upload/');

Do I need a second "users_files" table? I don't understand this part in the upload example:

   Mjoin::inst( 'files' )
        ->link( 'users.id', 'users_files.user_id' )
        ->link( 'files.id', 'users_files.file_id' )

Can anyone explain this part to me?

I already changed a lot, so it would be hard to review my whole code, but if anyone interested in it than I can publish it.

Thanks in advance

pib

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can anyone explain this part to me?

    The Mjoin->link() method and it being called twice (to define a link table) is detailed here. Rather than just repeating the manual, if you have any questions about it, feel free to ask.

    Regarding the error - does the JSON return from the server contain any other details?

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    I always got this response:

    <br />
    <b>Fatal error</b>:  Function name must be a string in <b>C:\Users\...\editor\php\Editor\Upload.php</b> on line <b>382</b><br />
    

    The error seems based on the $res = row:

    // Validation - custom callback
                    for ( $i=0, $ien=count($this->_validators) ; $i<$ien ; $i++ ) {
                            $res = $this->_validators[$i]( $upload );
    
                            if ( is_string( $res ) ) {
                                    $this->_error = $res;
                                    return false;
                            }
                    }
    

    My link looks now like this:

            Mjoin::inst( 'files' )
                ->link( '_stocks_fees.id', 'users_files.user_id' )
                ->link( 'files.id', 'users_files.file_id' )
    

    Is it possible to get a paid extra support to solve this issue?

    Kind regards

    pib

    I attached also my both files tables. May be it helps

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi,

    Could you check what version of the Editor PHP libraries you are using please? If not v1.7.0, could you upgrade? In that (currently the latest version), line 382 in Upload.php is $id = null; which suggests to me you might be using an older version of the software, possibly with a bug that has been addressed.

    Regarding paid support - we'll solve this one without the paid support, but don't let me stop you if you want to pick it up :).

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0
    edited January 2018

    Hi,

    the upgrade helped a bit. Now the files get storred in the upload folder and I also get entries in the "files" table.

    Unfortunately the "users_files" table is still empty. I guess the main reason must be here:

    ->link( '_stocks_fees.id', 'users_files.user_id' )
                ->link( 'files.id', 'users_files.file_id' )
    

    Do you have an ideas where the reason for the emtpy "users_files" table is?

    Attached you will find my API code for the child tables.

    Thank you so much for your support

    pib

    PS: If I create an entry in the "users_files" table manually than the API will show the file id in the Array

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited January 2018

    Unfortunately the "users_files" table is still empty.

    It will be empty until you submit the form (i.e. when the link between the user and the image is established). Are you using the uploadMany field type? Can you show me your Javascript code for this?

    Thanks,
    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Yes I am using upload-many field type. In the start.html you will see the complete code and the "uploadMany" area begins in line 590-

    I also submited the form and got the entry in the files table, but not in users_files table.

    Thanks you very much

    Pib

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Thanks. I don't see anything wrong on the client-side there. Could you show me your full PHP script please? At the moment I've only got snippets from above.

    Thanks,
    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Hi,

    I attached both php files and upload the complete solution on http://wechselstube.host4free.de/intern/start5.php (you can delete and add entries if you want, it's just a test database).

    The upload still works on this server and I also got entries in the "files" tables but not in the "users_files" table. You can also see the current database (no entries) at http://wechselstube.host4free.de/intern/db.txt

    Kind regards

    pib

This discussion has been closed.