YII2 download PDF from image field

Hi,

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;

        $dataReader=$conn->createCommand($sql)->query();

        $dataReader->bindColumn(1,$file,PDO::PARAM_LOB,0,PDO::SQLSRV_ENCODING_BINARY);

        $dataReader->setFetchMode(PDO::FETCH_BOUND);

        while($dataReader->read()!==false)

        {


            header("Content-type:application/pdf");

            echo $file;

        }



Thanks for your help