Proper header php mysql blob display image
I’m having trouble setting the page header which i believe needs to be set as an image.
So, this shows the image but I do not believe the page header is correct:
//header("Content-type: image/png"); echo '<img src="data:image/png;base64,' . base64_encode( $row['image1'] ) . '" />';
However, this does not show my image:
header("Content-type: image/png"); echo '<img src="data:image/png;base64,' . base64_encode( $row['image1'] ) . '" />';
What am I missing? I believe the image should show when the header is set to image/png but i’m getting an error that it cannot be displayed because of errors.
- To retrieve BLOB image from sqlite
- Storing blobs in external location using built-in CoreData option
- How to upload the Users profile pic and how to fetch that profile pic from another users device?
- Retrieve nsdata from sqlite stored in Blob data type for iPhone App
- blob does not accept Uint8Array on ios
- Storing images in Core Data or as file?
Solutions Collect From Internet About “Proper header php mysql blob display image”
This tells your browser that you’re about to pass it raw binary data that is a PNG file. So anything output after that would have to be a binary PNG. You can’t then place HTML and expect that to work
echo '<img src="data:image/png;base64,' . base64_encode( $row['image1'] ) . '" />';
This works because you’re base64 encoding your image (translates binary into text), outputting that to the browser and then telling your browser to interpret it as base64.
If you want to output the raw binary data you have to rearrange the order. So here’s your HTML
<img src="image.php" />
Now you’ll note the
src points to a PHP file. That’s because we’re going to have that PHP file return an image. Here’s what
image.php would look like
//Your query here $row = mysqli_fetch_assoc($result); header("Content-type: image/png"); echo $row['image1'];
This works because the browser will call the PHP file, expecting an image. The
header tells the browser that this is a PNG file and you can now dump your binary PNG data.
- multithread database fetch xcode
- What do the memory addresses in iPhone crash logs signify?
- Why do I get “could not be added to your itunes library because it is not a valid app” error when trying to install Ad-Hoc build?
- Swift – How to mutate a struct object when iterating over it
- How to skip the login scene and start straight from the next if you are already authorized?
- Adding string on existing txt file -iOS
- does my app display second time notification iOS 9
- Get JSON result with GET request and parameters with Alamofire
- Swift 3 and EKEventStoreRequestAccessCompletionHandler throwing exception
- How to enable UIDragInteraction on Custom UIViews for iPhone
- Localize Asset Catalogs
- MPMoviePlayerPlaybackDidFinishNotification being called again in iPhone 4.3 simulator when setting contentURL
- How do I save the contents of a UIWebView as an image
- Avoiding circular retention using ARC (strong/weak), learning some basics
- How to get IMEI on iPhone 5