Unable to get uploadMany work

Unable to get uploadMany work

victorlauvictorlau Posts: 2Questions: 1Answers: 0

Hello!
I'm trying to upload many documents following the example in editor, but I guess I'm having the error while joining the two tables.

Editor::inst( $db, 'staff' )
    ->fields(
        Field::inst( 'name' ),
        Field::inst( 'position' ),
        Field::inst( 'office' ),
        Field::inst( 'ext' ),
        Field::inst( 'salary' )
            ->validator( Validate::numeric() )
            ->setFormatter( Format::ifEmpty(null) ),
        Field::inst( 'start_date' )
            ->validator( Validate::dateFormat( 'Y-m-d' ) )
            ->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
            ->setFormatter( Format::dateFormatToSql('Y-m-d' ) )
    )    
            ->join(
                Mjoin::inst( 'files' )
                    ->link( 'staff.id', 'files.id' )
                    ->link( 'files.id', 'staff.id' )
                    ->fields(
                        Field::inst( 'id' )
                            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' )
                                ->db( 'files', 'id', array(
                                    'filename'    => Upload::DB_FILE_NAME,
                                    'filesize'    => Upload::DB_FILE_SIZE,
                                    'web_path'    => Upload::DB_WEB_PATH,
                                    'system_path' => Upload::DB_SYSTEM_PATH
                                ) )
                                ->validator( Validate::fileSize( 500000, 'Files must be smaller that 500K' ) )
                                ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' , 'pdf' ), "Please upload a file" ) )
                            )
                    )
            )
->process( $_POST )
->json();

These are the tables I'm using

CREATE TABLE files (
id int(11) NOT NULL,
filename varchar(200),
filesize int(4) UNSIGNED,
web_path varchar(100),
system_path varchar(200),
PRIMARY KEY (id)
)

CREATE TABLE staff (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(100),
position varchar(100),
office varchar(100),
ext int(2) UNSIGNED,
start_date date,
salary int(4) UNSIGNED,
files varchar(100),
PRIMARY KEY (id)
)

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Are you seeing any errors from the server? You might get some in the response,

    Colin

  • victorlauvictorlau Posts: 2Questions: 1Answers: 0

    I get:

    DataTables warning: table id=staff - An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'staff'.

    Thanks

Sign In or Register to comment.