S
S
Sergey Defactov2018-03-23 09:08:09
PHP
Sergey Defactov, 2018-03-23 09:08:09

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);
    }
  }
}

But on the new cms there is no such thing. Images in the database are stored in the usual way to the image . They
have a function , how can you decode the base64 format from the database into a normal path with this function
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

2 answer(s)
O
Oleg, 2018-03-23
@402d

you just need to put them in the form of files in the right paths

K
Kirill Gorelov, 2018-03-23
@Kirill-Gorelov

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);

Then you change this picture and put it in the folder you need.
ps if I understand your problem and task correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question