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

前端 未结 2 1787
灰色年华
灰色年华 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:13

    This is the most common problem faced while dealing with the blob file. From your example, I can see that you are saving "fileType" as the extensions of the files (i.e 'jpg' for images, 'pdf' for pdf files etc.), you are uploading. But instead of that you can can save file type as the MIME content type.

    Suppose if you upload a jpeg image - the MIME type will be stored in the "fileType" as the "image/jpeg". Similarly for pdf it will be stored as "application/pdf". I designed code like this to download the blob file from the database. I am going to assume that the files are already uploaded into the database table you created.

    Database table "uploads"

    | fileID | fileName | fileType | fileSize |fileData | userID |

    download.php

    
    

    You can find the complete code of blob-upload here.

提交回复
热议问题