staffing
New Member
- Messages
- 18
- Reaction score
- 0
- Points
- 1
Hey I wanted to know how to convert a base64 data:image to a link on my website, I have this article poster and when you upload images it'll use the base64 link instead of uploading automatically, so I wanted to create a function that would grab the base64 link, covert it/upload it to my images directory and then push it all to my database
The current problem I'm having is simply converting the base64 to an image and uploading it, here is my code so far which i found on stackoverflow:
It's also returning expects parameter 1 to be resource, boolean given; That is simply a short version of what I need to do, I need to run this script within this function:
The current problem I'm having is simply converting the base64 to an image and uploading it, here is my code so far which i found on stackoverflow:
<?php
function base64_to_img($base64_string, $output_file) {
$output_file = $_GET['filename'];
$output_dir = "/images/";
$ifp = fopen($output_dir.$output_file, "wp");
$data = explode(',', $base64_string);
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $output_file;
}
$string = 'data:image/png;base64,BASE64/IMAGE/URI/HERE'; // Too long to actually paste it all in here
base64_to_img($string, $output_file);
?>
My php error log is returning "Failed to open stream" - no such file/directoryfunction base64_to_img($base64_string, $output_file) {
$output_file = $_GET['filename'];
$output_dir = "/images/";
$ifp = fopen($output_dir.$output_file, "wp");
$data = explode(',', $base64_string);
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $output_file;
}
$string = 'data:image/png;base64,BASE64/IMAGE/URI/HERE'; // Too long to actually paste it all in here
base64_to_img($string, $output_file);
?>
It's also returning expects parameter 1 to be resource, boolean given; That is simply a short version of what I need to do, I need to run this script within this function:
$doc = new DomDocument();
$doc->loadHTML($content);
$sub = $doc->getElementsByTagName("img");
foreach ($sub as $sub) {
$src = $tag->getAttribute('src');
}
Is this at all possible?$doc->loadHTML($content);
$sub = $doc->getElementsByTagName("img");
foreach ($sub as $sub) {
$src = $tag->getAttribute('src');
}