在PHP Mysql中下载完整大小的文件

I have a problem downloading the Blob file from MYSQL using php.

Here is my php script in downloading file:

        $querysel = "Select * from file where file_id = '$fileid'";
        $resultsel = mysql_query($querysel);
        $rowsel = mysql_fetch_array($resultsel);

        $filename = $rowsel['file_name'];
        $mimetype = $rowsel['mime_type'];
        $filesize = $rowsel['file_size'];

        header("Content-length: ".$filesize);
        header("Content-type: ".$mimetype);
        header("Content-disposition: attachment; filename=".$filename);
        header("Content-Description: PHP Generated Data");
        header("Content-transfer-encoding: binary");
        echo $filename;

And this table in mysql:enter image description here

PROBLEM   [UPDATED]

  1. What seems to be the problem here is that after downloading the file, the file size from that particular file don't match with the file size saved in mysql. I don't know why?

  2. I also encounter this small problem, After I downloaded the Powerpoint and delete it and download it again would be automatically saved to downloads and will automatically be opened. Is that normal?

Example:

The BLOB file with 6.8MB of file size was supposed to be downloaded with 6.8MB also but what happened here is that the file size of the downloaded file is only 25bytes. Why?

Any help would be much appreciated. Thanks

It seems to me you want to be echoing the file contents and not its filename

    $querysel = "Select * from file where file_id = '$fileid'";
    $resultsel = mysql_query($querysel);
    $rowsel = mysql_fetch_array($resultsel);

    $filename = $rowsel['file_name'];
    $mimetype = $rowsel['mime_type'];
    $filesize = $rowsel['file_size'];

    header("Content-length: ".$filesize);
    header("Content-type: ".$mimetype);
    header("Content-disposition: attachment; filename=".$filename);
    header("Content-Description: PHP Generated Data");
    header("Content-transfer-encoding: binary");

    echo $rowsel['file_content'];          //<-- changed line

Of course you still probably have a problem with the larger files in that a BLOB is not large enough to hold 6.8 Meg. See @Fred-ii- comment for details and links to all the relevant info you need to check that.

Even a LONGBLOB is only 4,294,967,295 bytes, thats a little over 4Gig, so you probably need to do some size checking before storing to even a LONGBLOB.

The safest suggestion would be to store the actual files on disk and only the filename and path in the database.