I try to send a file to the user with this function
Yii::$app->response->sendFile($tmp_filename, 'test.RData');
Now I want the file to be deleted after sending. I know that there's an event handler for send
method in yii/web/Response
called EVENT_AFTER_SEND
I tried to access this handler with the following code:
Event::on(\yii\web\Response::className(), \yii\web\Response::EVENT_AFTER_SEND, function ($event) {
unlink($event->response->filename);
});
But my problem is
a) I'm not sure if this is the right way
b) how to access the filename inside the event
Any help is appreciated!