File Upload on multiple datatables

File Upload on multiple datatables

cbasmadjiancbasmadjian Posts: 56Questions: 14Answers: 0
edited November 2016 in Free community support

Hello,

Just to let you know my current setup is using this blog (https://datatables.net/blog/2016-03-25) to have the Parent / Child. This configuration is working just fine, but I would like to have my child datatable to include some uploading features. The error that I am receiving is the "A server error occurred while uploading the file" I have some ideas as to why this is occurring, but I am uncertain.

Trying my best to use this example (https://editor.datatables.net/examples/advanced/upload.html) to configure the upload feature to be used on my child datatable.

Server Side Code

if(($var1== "true") && (is_numeric($_POST['ForeignKey']) || isset($_POST['ForeignKey']))) {
            $mediaLibrary = Editor::inst( $db, 'TableName', 'ID' );
            $mediaLibrary->fields(
                    Field::inst( 'TableName.Field' )->validator( 'Validate::required' ),
                    Field::inst( 'TableName.Field' )
                        ->upload( Upload::inst( '/.../helloworld.png' ) //$_SERVER['DOCUMENT_ROOT'].'/upload/__ID__.__EXTN__' 
                            ->db( 'TableName', 'ID', array(
                                'TableName.Field' => 'helloworld'
                            ) )
                            ->validator( function ( $file ) {
                                return$file['size'] >= 5000000 ?
                                    "Files must be smaller than 5 MB" :
                                    null;
                            } )
                            ->allowedExtensions( array( 'png' ), "Please upload an image" )
                        )
                    Field::inst( 'TableName.Field' ),
                    Field::inst( 'TableName.Field' ),
                    Field::inst( 'TableName.Field' ),
                    Field::inst( 'TableName.Field' ),
                    Field::inst( 'TableName.Field' ),
                    Field::inst( 'TableName.Field' ),
                    Field::inst( 'TableName.ForeignKey' ),
                    Field::inst( 'TableName.Field' )
                )
                ->leftJoin( 'ParentTable', 'ParentTable.ID', '=', 'TableName.ForeignKey' )
                ->where( 'ForeignKey', $_POST['ForeignKey'] )
                ->process($_POST)
                ->json();
        }
        else{
            echo json_encode( [ "data" => [] ] );
        }

My first thought as to what may be wrong is this line "Field::inst( 'TableName.Field' )" right before the ->upload has no comma ",". Not sure if that needs to be there (forgive me but my PHP is a bit rusty. Not sure if my syntax is correct).

My second thought was the location of where the file is being stored is not correct. Hence, the reason why I hardcoded the directory and still get the same results.

As I mentioned at the beginning of this post is the blog post of the Parent/Child datatable. That was my third thought that what if my conditional statements are preventing the upload because it doesn't know where to go. Not sure if this has a cause to this and Chrome's Network tab offers me very little information to help debug this.

------WebKitFormBoundarycov8M67Aslz2L2Bi
Content-Disposition: form-data; name="action"

upload
------WebKitFormBoundarycov8M67Aslz2L2Bi
Content-Disposition: form-data; name="uploadField"

TableName.Field
------WebKitFormBoundarycov8M67Aslz2L2Bi
Content-Disposition: form-data; name="upload"; filename="DiamondsByGia_Plugins.png"
Content-Type: image/png

------WebKitFormBoundarycov8M67Aslz2L2Bi--

Any help would be greatly appreciated.

Thank you.

Answers

  • allanallan Posts: 63,822Questions: 1Answers: 10,517 Site admin

    Not sure if this has a cause to this and Chrome's Network tab offers me very little information to help debug this.

    What does the "Response" tab show? Does it show anything? If nothing at all, have a look in your server's error logs to see if there is an error reported there.

    Allan

This discussion has been closed.