简体   繁体   中英

Failed to load image from MySQL to PHP page

I creating a system that contains android apps (for user) and web (for admin). In Android apps, there a camera function that allowed the user to snap the photo and store the photo to the MySQL database. I use method Encode Base64 to store the image to the database and Decode Base64 to display back the image from the database to the Android Apps. The image formate that store at the MySQL is BLOB. At Android Apps, everything runs well. Below is the current code for encode decode at android apps:

public static String bitmapToBase64(Bitmap image) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    image.compress(Bitmap.CompressFormat.JPEG, 100, os);
    byte[] byteArray = os.toByteArray();
    String encodedImageString = Base64.encodeToString(byteArray, Base64.DEFAULT);
    return encodedImageString ;
}

public static Bitmap base64ToBitmap(String encodedString) {
    byte[] decodedString = Base64.decode(encodedString, Base64.DEFAULT);
    Bitmap bitmap= BitmapFactory.decodeByteArray(decodedString , 0,
            decodedString.length);
    return bitmap;
}

Now, I want to display the image from database to web. The web that I developed is using PHP. When I display the image, the image will display like this:

在此处输入图像描述

Below is the PHP code that I use to display the image from database to php page

echo "<td align='center'><img src='data:image/jpeg;base64,".base64_encode($row["photo_before"])."'/></td>";

Can I know what is the problem? How to solve it?

Use $row["photo_before"] directly.

echo "<td align='center'>
      <img src='".$row["photo_before"]."'/> 
      </td>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM