使用php从我电脑的文件夹中检索图像


Retrieve image from folder in my computer using php

我试图使用以下代码从服务器检索图像,但它不起作用:

<?php
    $result=file_get_contents("http://192.168.43.89/phpmyadmin/uploads/8.jpg");   
    header("content-type:image/jpeg");
    echo '<img src="' .base64_decode($result). '">';
?>

首先需要使用base64_encode()对提取到base64的图像数据进行编码,然后必须将数据正确地包含在src-属性中(语法:data:[<mediatype>][;base64],<data>),如下所示:

<?php
    $result=base64_encode(file_get_contents("http://192.168.43.89/phpmyadmin/uploads/8.jpg"));   
    //header("content-type:image/jpeg"); --> you don't need this if you are outputting HTML, only if you are outputting the image directly
    echo "<img src='"data:image/jpeg;base64,$result'">";
?>

来源:http://www.websiteoptimization.com/speed/tweak/inline-images/