Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:09:12+00:00 2026-06-01T19:09:12+00:00

I am using Hotaru CMS with the Image Upload plugin, I get this error

  • 0

I am using Hotaru CMS with the Image Upload plugin, I get this error if I try to attach an image to a post, otherwise there is no error:

unserialize() [function.unserialize]: Error at offset

The offending code (error points to line with **):

/**
     * Retrieve submission step data
     *
     * @param $key - empty when setting
     * @return bool
     */
    public function loadSubmitData($h, $key = '')
    {
        // delete everything in this table older than 30 minutes:
        $this->deleteTempData($h->db);

        if (!$key) { return false; }

        $cleanKey = preg_replace('/[^a-z0-9]+/','',$key);
        if (strcmp($key,$cleanKey) != 0) {
            return false;
        } else {
            $sql = "SELECT tempdata_value FROM " . TABLE_TEMPDATA . " WHERE tempdata_key = %s ORDER BY tempdata_updatedts DESC LIMIT 1";
            $submitted_data = $h->db->get_var($h->db->prepare($sql, $key));
            **if ($submitted_data) { return unserialize($submitted_data); } else { return false; }** 
        }
    }

Data from the table, notice the end bit has the image info, I am not an expert in PHP so I was wondering what you guys/gals might think?

tempdata_value:

a:10:{s:16:"submit_editorial";b:0;s:15:"submit_orig_url";s:13:"www.bbc.co.uk";s:12:"submit_title";s:14:"No title found";s:14:"submit_content";s:12:"dnfsdkfjdfdf";s:15:"submit_category";i:2;s:11:"submit_tags";s:3:"bbc";s:9:"submit_id";b:0;s:16:"submit_subscribe";i:0;s:15:"submit_comments";s:4:"open";s:5:"image";s:19:"C:fakepath100.jpg";}

Edit: I think I’ve found the serialize bit…

/**
     * Save submission step data
     *
     * @return bool
     */
    public function saveSubmitData($h)
    {
        // delete everything in this table older than 30 minutes:
        $this->deleteTempData($h->db);

        $sid = preg_replace('/[^a-z0-9]+/i', '', session_id());
        $key = md5(microtime() . $sid . rand());
        $sql = "INSERT INTO " . TABLE_TEMPDATA . " (tempdata_key, tempdata_value, tempdata_updateby) VALUES (%s,%s, %d)";
        $h->db->query($h->db->prepare($sql, $key, serialize($h->vars['submitted_data']), $h->currentUser->id));
        return $key;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:09:13+00:00Added an answer on June 1, 2026 at 7:09 pm

    unserialize() [function.unserialize]: Error at offset was dues to invalid serialization data due to invalid length

    Quick Fix

    What you can do is is recalculating the length of the elements in serialized array

    You current serialized data

    $data = 'a:10:{s:16:"submit_editorial";b:0;s:15:"submit_orig_url";s:13:"www.bbc.co.uk";s:12:"submit_title";s:14:"No title found";s:14:"submit_content";s:12:"dnfsdkfjdfdf";s:15:"submit_category";i:2;s:11:"submit_tags";s:3:"bbc";s:9:"submit_id";b:0;s:16:"submit_subscribe";i:0;s:15:"submit_comments";s:4:"open";s:5:"image";s:19:"C:fakepath100.jpg";}';
    

    Example without recalculation

    var_dump(unserialize($data));
    

    Output

    Notice: unserialize() [function.unserialize]: Error at offset 337 of 338 bytes
    

    Recalculating

    $data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $data);
    var_dump(unserialize($data));
    

    Output

    array
      'submit_editorial' => boolean false
      'submit_orig_url' => string 'www.bbc.co.uk' (length=13)
      'submit_title' => string 'No title found' (length=14)
      'submit_content' => string 'dnfsdkfjdfdf' (length=12)
      'submit_category' => int 2
      'submit_tags' => string 'bbc' (length=3)
      'submit_id' => boolean false
      'submit_subscribe' => int 0
      'submit_comments' => string 'open' (length=4)
      'image' => string 'C:fakepath100.jpg' (length=17)
    

    Recommendation .. I

    Instead of using this kind of quick fix … i”ll advice you update the question with

    • How you are serializing your data

    • How you are Saving it ..

    ================================ EDIT 1 ===============================

    The Error

    The Error was generated because of use of double quote " instead single quote ' that is why C:\fakepath\100.png was converted to C:fakepath100.jpg

    To fix the error

    You need to change $h->vars['submitted_data'] From (Note the singe quite ' )

    Replace

     $h->vars['submitted_data']['image'] = "C:\fakepath\100.png" ;
    

    With

     $h->vars['submitted_data']['image'] = 'C:\fakepath\100.png' ;
    

    Additional Filter

    You can also add this simple filter before you call serialize

    function satitize(&$value, $key)
    {
        $value = addslashes($value);
    }
    
    array_walk($h->vars['submitted_data'], "satitize");
    

    If you have UTF Characters you can also run

     $h->vars['submitted_data'] = array_map("utf8_encode",$h->vars['submitted_data']);
    

    How to detect the problem in future serialized data

      findSerializeError ( $data1 ) ;
    

    Output

    Diffrence 9 != 7
        -> ORD number 57 != 55
        -> Line Number = 315
        -> Section Data1  = pen";s:5:"image";s:19:"C:fakepath100.jpg
        -> Section Data2  = pen";s:5:"image";s:17:"C:fakepath100.jpg
                                                ^------- The Error (Element Length)
    

    findSerializeError Function

    function findSerializeError($data1) {
        echo "<pre>";
        $data2 = preg_replace ( '!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'",$data1 );
        $max = (strlen ( $data1 ) > strlen ( $data2 )) ? strlen ( $data1 ) : strlen ( $data2 );
    
        echo $data1 . PHP_EOL;
        echo $data2 . PHP_EOL;
    
        for($i = 0; $i < $max; $i ++) {
    
            if (@$data1 {$i} !== @$data2 {$i}) {
    
                echo "Diffrence ", @$data1 {$i}, " != ", @$data2 {$i}, PHP_EOL;
                echo "\t-> ORD number ", ord ( @$data1 {$i} ), " != ", ord ( @$data2 {$i} ), PHP_EOL;
                echo "\t-> Line Number = $i" . PHP_EOL;
    
                $start = ($i - 20);
                $start = ($start < 0) ? 0 : $start;
                $length = 40;
    
                $point = $max - $i;
                if ($point < 20) {
                    $rlength = 1;
                    $rpoint = - $point;
                } else {
                    $rpoint = $length - 20;
                    $rlength = 1;
                }
    
                echo "\t-> Section Data1  = ", substr_replace ( substr ( $data1, $start, $length ), "<b style=\"color:green\">{$data1 {$i}}</b>", $rpoint, $rlength ), PHP_EOL;
                echo "\t-> Section Data2  = ", substr_replace ( substr ( $data2, $start, $length ), "<b style=\"color:red\">{$data2 {$i}}</b>", $rpoint, $rlength ), PHP_EOL;
            }
    
        }
    
    }
    

    A better way to save to Database

    $toDatabse = base64_encode(serialize($data));  // Save to database
    $fromDatabase = unserialize(base64_decode($data)); //Getting Save Format 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using NSDateComponents I know how to get the day component, but this gives me
using file_get_contents , I open an Internet URL and get the contents of this
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using the HTML5 File API I can get the Binary String representation of a
Using this code, the following execution yields strange results: C 100 R W The
using xmltextreader, how would I load a hashtable. XML: <base><user name=john>2342343</user><user name=mark>239099393</user></base> This was
Using Visual SourceSafe's Open SourceSafe Database... command, there is an option at the bottom
Using php's DOMDocument->LoadHTMLFile('test.html'); keeps on returning an error to me, reporting for an error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.