How to convert an image to base64 encoding?

前端 未结 9 1348
刺人心
刺人心 2020-11-22 06:01

Can you please guide me how can I convert an image from a URL to base64 encoding?

9条回答
  •  梦如初夏
    2020-11-22 06:34

    Here is the code for upload to encode and save it to the MySQL

    if (!isset($_GET["getfile"])) {
        if ($_FILES["file"]["error"] > 0) {
            echo "Error: " . $_FILES["file"]["error"] . "
    "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]); $bin_string = file_get_contents($_FILES["file"]["name"]); $hex_string = base64_encode($bin_string); $mysqli = mysqli_init(); if (!$mysqli->real_connect('localhost', 'root', '', 'arihant')) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } $mysqli->query("INSERT INTO upload(image) VALUES ('" . $hex_string . "')"); } }

    For showing the image use this

    echo "";
    

提交回复
热议问题