Actions after uploading a file

Actions after uploading a file

MaikelMaikel Posts: 45Questions: 12Answers: 1

Hey,

i'm using a standalone editor to do some upload of files, but after the upload i want to run some custom functions (server side is php) on the uploaded file, and then store the output of these functions either in the returned json or in the db.

How would i handle this? what hook should i use for it?

Maikel

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 48,908Questions: 1Answers: 7,132 Site admin

    The postUpload event in the server-side libraries is the one you want here.

    Allan

  • MaikelMaikel Posts: 45Questions: 12Answers: 1

    indeed, thats the event, but how can i push some data into the returning json?

  • allanallan Posts: 48,908Questions: 1Answers: 7,132 Site admin
    Answer ✓

    You'd need to do something like:

    $extra = [];
    $editor = Editor::inst( ... )
      ->field( ... )
      ->on( 'postUpload', function ( ... ) use ( $extra ) {
        $extra = 1; // or whatever
      } );
    
    $data = $editor
      ->process( $_POST )
      ->data();
    
    $data['extra'] = $extra;
    
    echo json_encode( $data );
    

    Allan

Sign In or Register to comment.