Duplicate Blob field with foreach

Posted by JGSilva on Stack Overflow See other posts from Stack Overflow or by JGSilva
Published on 2012-12-11T11:02:33Z Indexed on 2012/12/11 11:03 UTC
Read the original article Hit count: 222

Filed under:
|

I have some fields (blob) where I have uploaded some images. The images display correctly and I can open it without problem in Photoshop for example.

I created a button where user can duplicate the product and everything works fine, but when it comes to duplicate the image entry I got some errors, like 1064 and others ones that I can't remember cause I am working 3 days inside this.

Because de original product have 3 or more images I select then and gave an foreach.

What I notice when a print de blob is that in the end it eats the next array, like if don't have an end. In other words, the next item got inside that utf-8 character in the print.

That gave me some clue.

The next approach was to save it in somewhere, and reupload it. The problem is that only the first one works.

When I download the image saved, it opens normally so, it is not a saving in disk problem.

When I gave a print in the $result, the same happens, is like the image is hungry and ate the next one.

Here is the code.

Notice = I created the [$count] to see if was not an rewrite in array error.

Even tried to , in beging of the foreach, kind of clean the vars…

$count=0;
    foreach ($original_image as $key => $val)
    {
        $count++;
        //$arquivo = '';
        //$image = '';
        //$file = '';
        //$this->image = '';
        //$return = '';

        $arquivo[$count] = $val['pi_id'].'.'.$val['pi_type'];
        $image[$count] = $caminho_url.$arquivo[$count];

        if (file_exists($image[$count])) {
            $this->image = Image::factory($image[$count]);
            $this->image->save($image[$count]);
            $file[$count]=mysql_real_escape_string(addslashes(fread(fopen($image[$count], "r"), filesize($image[$count]))));
            $return[$count] = Product::add_image($id_prod, $file[$count], $val['pi_type'],$val['pi_main']);
        }else {
            die('no');  
        }
    }

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql