When attempting to display an image stored as a BLOB in a MySQL database, developers often encounter an issue where any text echoed before or after the image's header causes the image to display incorrectly.
The problem arises because the web browser interprets any text echoed outside the image data stream as part of the image. This is due to the fact that the header and image data must be delivered continuously and without interruption.
To display other items and the image together without interruption, you can convert the image data into base64 and embed it within an tag. This approach allows you to include text and other elements in the HTML output while still displaying the image.
Here's a revised version of the code:
echo '';
echo 'Hello world.';
Note: While this solution allows you to display both the image and other text, it's not ideal because it cannot be cached and can be slow on mobile devices. Consider checking the caniuse documentation for more information on data URIs.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3