How to display an BLOB image stored in MySql database?

前端 未结 4 2110
孤城傲影
孤城傲影 2020-11-30 11:56

I am trying to display the last 5 images uploaded to my \"store\" table in MySql. I\'m a complete noob to PHP and databases and i\'ve been reading a lot on how to do this bu

4条回答
  •  遥遥无期
    2020-11-30 12:31

    You can also use this function

    //Retrieve image from database and display it on html webpage    
    function displayImageFromDatabase(){    
    //use global keyword to declare conn inside a function    
    global $conn;    
    $sqlselectimageFromDb = "SELECT * FROM `imageuploadphpmysqlblob` ";    
    $dataFromDb = mysqli_query($conn, $sqlselectimageFromDb);    
    while ($row = mysqli_fetch_assoc($dataFromDb)) {    
    echo '';    
    }
    

    Insert it into mysql database like this :

    $image = $_FILES['imagefile']['tmp_name'];
    $name = $_FILES['imagefile']['name'];
    $image = base64_encode(file_get_contents(addslashes($image)));
    

    references : https://mauricemutetingundi.blogspot.com/2019/04/how-to-upload-blob-image-to-mysql.html

提交回复
热议问题