upload to directorystructure

upload to directorystructure

FicosFicos Posts: 88Questions: 22Answers: 0

Please find below a part of the serverscript. I have read the File Upload section of the manual as well as the custom upload actions. My problem is that the file needs to be uploaded to the directory represented by ../uploads/archief01.rec_client/NAME where the value client07.NUMMER is the value of the first field of the editor. How do I reference to that value?

Field::inst( 'archief01.rec_client' )
                    ->validator( 'Validate::notEmpty' )
            ->options( Options::inst()
                ->table( 'client07' )
                ->value( 'NUMMER' )
                ->label( array('NAAM','client07.VOLET') )
                ->order( 'ZOEK asc' )
                ->where( function ($q) {
                    $q->where( 'client07.ISCLIENT', '1', '=' );
                    $q->where( 'client07.ARCHIEF', '0', '=' );
                    $q->where('client07.BLOKKEER','0','=');
                })
                ->render( function ( $row ) {
                    return $row['NUMMER'].' '.$row['NAAM'].' '.$row['client07.VOLET'];
                })
        ),
        Field::inst('archief01.image' )
    ->upload(
        Upload::inst( function ( $file, $id ) {
            move_uploaded_file( $file['tmp_name'], '/uploads/'.archief01.rec_client.'/'.$id );
            return $id;
        } )
            ->db( 'image', 'id', array(
                'fileName' => Upload::DB_FILE_NAME,
                'fileSize' => Upload::DB_FILE_SIZE
            ) )
    )
    ->setFormatter( 'Format::nullEmpty' );
}

$id is the primary key for the file.
Currently this gives a json error because reference to archief01.rec_client is not yet populated.
Thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    where the value client07.NUMMER is the value of the first field of the editor. How do I reference to that value?

    The issue here is that the file upload is performed async to the rest of the form. So for example, if you click the "New" button, you can then upload a file. At that point there will not be a NUMMER value for that row - since the row doesn't yet exist.

    The file path can only be defined by the information from the file itself, or the session. Not from the other data in the form.

    Allan

This discussion has been closed.