PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 16, 2022

[FIXED] Retrieving image (Resource id #245) instead of base64

 March 16, 2022     base64, blob, cakephp, cakephp-3.x, php     No comments   

Issue

I am developing a website using Cakephp and I am uploading an image in the database as a BLOB. Now when I am retrieving the BLOB data from my Cakephp code I am receiving a text "Resource id #245". How can I convert this into base64?

Displaying image code

foreach($foods as $food)
{
   echo $food->image;
}

Result in

Resource id #245 (I need this as a base64)

CakePhp Version 3.8


Solution

Binary column types will automatically be associated with the \Cake\Database\Type\BinaryType database type, which will return the data as a stream.

So you can use Filesystem and Stream functions to read the data, and turn it into whatever you want, like:

$binaryData = stream_get_contents($food->image);
$base64Data = base64_encode($binaryData);


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing