How to convert image path to base64 encode data using PHP
I need to convert the image URL to base64_encode
data using PHP. I am explaining my code below.
<?php
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
?>
Here I am getting the blank output. Please help me to resolve this issue.
php base64
add a comment |
I need to convert the image URL to base64_encode
data using PHP. I am explaining my code below.
<?php
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
?>
Here I am getting the blank output. Please help me to resolve this issue.
php base64
Enable the error logs. This path does not exist
– pr1nc3
Nov 19 '18 at 12:46
I have changed the original path. In my case path is correct.
– subhra
Nov 19 '18 at 12:48
The above code returns the result in base64_encoding format. I don't get what's the error. Enable your error log. Blank page is never "blank" there are errors that are hidden there.
– pr1nc3
Nov 19 '18 at 12:51
Duplicate of stackoverflow.com/questions/3967515/…
– akshaypjoshi
Nov 19 '18 at 14:12
Possible duplicate of How to convert an image to base64 encoding?
– akshaypjoshi
Nov 19 '18 at 14:12
add a comment |
I need to convert the image URL to base64_encode
data using PHP. I am explaining my code below.
<?php
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
?>
Here I am getting the blank output. Please help me to resolve this issue.
php base64
I need to convert the image URL to base64_encode
data using PHP. I am explaining my code below.
<?php
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
?>
Here I am getting the blank output. Please help me to resolve this issue.
php base64
php base64
edited Nov 19 '18 at 12:49
subhra
asked Nov 19 '18 at 12:41
subhrasubhra
1,34211134
1,34211134
Enable the error logs. This path does not exist
– pr1nc3
Nov 19 '18 at 12:46
I have changed the original path. In my case path is correct.
– subhra
Nov 19 '18 at 12:48
The above code returns the result in base64_encoding format. I don't get what's the error. Enable your error log. Blank page is never "blank" there are errors that are hidden there.
– pr1nc3
Nov 19 '18 at 12:51
Duplicate of stackoverflow.com/questions/3967515/…
– akshaypjoshi
Nov 19 '18 at 14:12
Possible duplicate of How to convert an image to base64 encoding?
– akshaypjoshi
Nov 19 '18 at 14:12
add a comment |
Enable the error logs. This path does not exist
– pr1nc3
Nov 19 '18 at 12:46
I have changed the original path. In my case path is correct.
– subhra
Nov 19 '18 at 12:48
The above code returns the result in base64_encoding format. I don't get what's the error. Enable your error log. Blank page is never "blank" there are errors that are hidden there.
– pr1nc3
Nov 19 '18 at 12:51
Duplicate of stackoverflow.com/questions/3967515/…
– akshaypjoshi
Nov 19 '18 at 14:12
Possible duplicate of How to convert an image to base64 encoding?
– akshaypjoshi
Nov 19 '18 at 14:12
Enable the error logs. This path does not exist
– pr1nc3
Nov 19 '18 at 12:46
Enable the error logs. This path does not exist
– pr1nc3
Nov 19 '18 at 12:46
I have changed the original path. In my case path is correct.
– subhra
Nov 19 '18 at 12:48
I have changed the original path. In my case path is correct.
– subhra
Nov 19 '18 at 12:48
The above code returns the result in base64_encoding format. I don't get what's the error. Enable your error log. Blank page is never "blank" there are errors that are hidden there.
– pr1nc3
Nov 19 '18 at 12:51
The above code returns the result in base64_encoding format. I don't get what's the error. Enable your error log. Blank page is never "blank" there are errors that are hidden there.
– pr1nc3
Nov 19 '18 at 12:51
Duplicate of stackoverflow.com/questions/3967515/…
– akshaypjoshi
Nov 19 '18 at 14:12
Duplicate of stackoverflow.com/questions/3967515/…
– akshaypjoshi
Nov 19 '18 at 14:12
Possible duplicate of How to convert an image to base64 encoding?
– akshaypjoshi
Nov 19 '18 at 14:12
Possible duplicate of How to convert an image to base64 encoding?
– akshaypjoshi
Nov 19 '18 at 14:12
add a comment |
4 Answers
4
active
oldest
votes
Here's code to convert image to base64 format
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo $base64;
Thanks
add a comment |
your code is working for me. I suppose the error is that in php.ini is disallowed to open remote urls: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen set it to true
add this line and check for error message
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
add a comment |
Please use the unescaped url in $path variable,
<?php
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
add a comment |
Try this code. It will help you.
According to his question, he needs to encode the image path. First, check if the image exists, if yes then encode its path .
$path = 'your-file-path';
$file = 'your-file';
$image_with_path = $path.'/'.$file;
if(file_exists($image_with_path)){
$base64 = base64_encode($image_with_path );
}
1
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374888%2fhow-to-convert-image-path-to-base64-encode-data-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's code to convert image to base64 format
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo $base64;
Thanks
add a comment |
Here's code to convert image to base64 format
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo $base64;
Thanks
add a comment |
Here's code to convert image to base64 format
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo $base64;
Thanks
Here's code to convert image to base64 format
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
echo $base64;
Thanks
answered Nov 19 '18 at 12:48
GulshanGulshan
324318
324318
add a comment |
add a comment |
your code is working for me. I suppose the error is that in php.ini is disallowed to open remote urls: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen set it to true
add this line and check for error message
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
add a comment |
your code is working for me. I suppose the error is that in php.ini is disallowed to open remote urls: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen set it to true
add this line and check for error message
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
add a comment |
your code is working for me. I suppose the error is that in php.ini is disallowed to open remote urls: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen set it to true
add this line and check for error message
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
your code is working for me. I suppose the error is that in php.ini is disallowed to open remote urls: http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen set it to true
add this line and check for error message
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$path='https://www.jquery-az.com/html/images/banana.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64=base64_encode($data);
print_r($base64);exit;
answered Nov 19 '18 at 12:53
myxaxamyxaxa
61036
61036
add a comment |
add a comment |
Please use the unescaped url in $path variable,
<?php
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
add a comment |
Please use the unescaped url in $path variable,
<?php
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
add a comment |
Please use the unescaped url in $path variable,
<?php
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
Please use the unescaped url in $path variable,
<?php
$path='http://abcd.com/pub/media/catalog/product//m/i/mi-l32m5-ai.jpeg';
answered Nov 19 '18 at 12:56
JeevanJeevan
1326
1326
add a comment |
add a comment |
Try this code. It will help you.
According to his question, he needs to encode the image path. First, check if the image exists, if yes then encode its path .
$path = 'your-file-path';
$file = 'your-file';
$image_with_path = $path.'/'.$file;
if(file_exists($image_with_path)){
$base64 = base64_encode($image_with_path );
}
1
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
add a comment |
Try this code. It will help you.
According to his question, he needs to encode the image path. First, check if the image exists, if yes then encode its path .
$path = 'your-file-path';
$file = 'your-file';
$image_with_path = $path.'/'.$file;
if(file_exists($image_with_path)){
$base64 = base64_encode($image_with_path );
}
1
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
add a comment |
Try this code. It will help you.
According to his question, he needs to encode the image path. First, check if the image exists, if yes then encode its path .
$path = 'your-file-path';
$file = 'your-file';
$image_with_path = $path.'/'.$file;
if(file_exists($image_with_path)){
$base64 = base64_encode($image_with_path );
}
Try this code. It will help you.
According to his question, he needs to encode the image path. First, check if the image exists, if yes then encode its path .
$path = 'your-file-path';
$file = 'your-file';
$image_with_path = $path.'/'.$file;
if(file_exists($image_with_path)){
$base64 = base64_encode($image_with_path );
}
edited Nov 20 '18 at 10:55
Martin
12.6k53579
12.6k53579
answered Nov 19 '18 at 12:49
Danish AliDanish Ali
1,1481819
1,1481819
1
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
add a comment |
1
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
1
1
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
How will this code help? Please explain your answer
– Martin
Nov 19 '18 at 14:29
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
I would have thought that with 700+ Rep you would have understood the ability to edit your post and write a conherent and full answer in your post.....
– Martin
Nov 20 '18 at 10:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374888%2fhow-to-convert-image-path-to-base64-encode-data-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Enable the error logs. This path does not exist
– pr1nc3
Nov 19 '18 at 12:46
I have changed the original path. In my case path is correct.
– subhra
Nov 19 '18 at 12:48
The above code returns the result in base64_encoding format. I don't get what's the error. Enable your error log. Blank page is never "blank" there are errors that are hidden there.
– pr1nc3
Nov 19 '18 at 12:51
Duplicate of stackoverflow.com/questions/3967515/…
– akshaypjoshi
Nov 19 '18 at 14:12
Possible duplicate of How to convert an image to base64 encoding?
– akshaypjoshi
Nov 19 '18 at 14:12