how to download blob based file from MySQL database in PHP?

前端 未结 2 1781
灰色年华
灰色年华 2020-12-03 16:15

How can i make a PHP script that will allow me to download a file from a database in MySQL. I have the following table named files where the uploaded file is sa

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 17:12

    you can use session and post filename and file content to download page

    session_start();
    $_SESSION['filename'] = $filename
    $_SESSION['file'] = $file
    echo "Download File"
    

    and in download.php use this code

    session_start();
    $filename = $_SESSION['filename'];
    $file = $_SESSION['file'];
    header("Content-Disposition: attachment; filename=$filename");
    ob_clean();
    flush();
    echo $file;
    

提交回复
热议问题