code-8
code-8

Reputation: 58810

Convert Image to Base64 PHP

I am 100% sure that I have a file on that path.

enter image description here

I'm trying to convert my logo.png to base64

$imagedata = file_get_contents("/images/account/operator/logo.png");
$base64 = base64_encode($imagedata);

I kept getting

file_get_contents(/images/account/operator/logo.png): failed to open stream: No such file or directory

Upvotes: 0

Views: 97

Answers (2)

fusion3k
fusion3k

Reputation: 11689

You have to use the absolute path:

$_SERVER['DOCUMENT_ROOT']. '/images/account/operator/logo.png'

Upvotes: 1

Sergey Vidusov
Sergey Vidusov

Reputation: 1342

You're using the absolute path. Unless there's an /images dir in your root folder on the server, file_get_contents() won't be able to access it. Modify your path to the image to use the correct value.

Upvotes: 2

Related Questions