YII2 download PDF from image field


i’m usign Yii2 with a MS SQL SERVER db.

I have a PDF file stored in an image field

Is it possible to download file.

i’ve tried in this way, but file is always corrupt

allegato is the image field’s name

        $conn = Yii::$app->db;

        $sql="SELECT allegato FROM documenti WHERE ID_documento = ".$id;







            echo $file;


Thanks for your help