Answer the question
In order to leave comments, you need to log in
Decode base64 image from db?
Good afternoon, I am transferring the site (db) to a new cms , in the old cms, the images were stored in base64 format, when output, they were decoded with these functions
if ($feed['photos']) {
$photos = @perfectUnserialize($feed['photos']);
$images = array();
if ($photos) {
foreach ($photos as $id => $pPath) {
try {
if (stripos(get_headers(url_img($pPath, 920))[0], "200 OK")) $images[$id] = $pPath;
} catch (Exception $e) {
$images[$id] = $pPath;
}
}
$feed['images'] = $images;
if (empty($feed['link_details']) && empty($feed['feed_content']) && empty($feed['images']) && empty($feed['video']) && empty($feed['files'])) $feed['empty'] = true;
}
}
if(!function_exists('perfectSerialize')) {
function perfectSerialize($string) {
return base64_encode(serialize($string));
}
}
if(!function_exists('perfectUnserialize')) {
function perfectUnserialize($string) {
if(base64_decode($string, true) == true) {
return @unserialize(base64_decode($string));
} else {
return @unserialize($string);
}
}
}
function Wo_GetMedia($media) {
global $wo;
$media = str_replace('%w', '200', $media);
if (empty($media)) {
return '';
}
if ($wo['config']['amazone_s3'] == 1) {
if (empty($wo['config']['amazone_s3_key']) || empty($wo['config']['amazone_s3_s_key']) || empty($wo['config']['region']) || empty($wo['config']['bucket_name'])) {
return $wo['config']['site_url'] . '/' . $media;
}
return $wo['config']['s3_site_url'] . '/' . $media;
}
return $wo['config']['site_url'] . '/' . $media;
}
Answer the question
In order to leave comments, you need to log in
If I understand the task correctly, you need to match the image in base64 format to existing paths in the new database???
I as understand at you id kratinok coincides in two DB?
If yes, then great. I see such an option.
You take an image in base64, make a file out of it, put it in and rename it to the path you need. That is, you take the path of the picture in the new database and actually create a new picture with the desired name and location.
You just have to think of taking the same image in base64 and the required entry from two new databases. And save.
You can save like this
//морально устаревший вариант
$decoded = base64_decode($src);
$fp = fopen($filename ,'w');
fwrite($fp, $decoded);
fclose($fp);
// и новый
$decoded = base64_decode($src);
file_put_content( $decoded);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question