Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-02-2007, 05:48 PM
Junior Member
 
Join Date: Sep 2007
Posts: 3
Unhappy Images inserted into MEDIUMBLOB column gets corrupted with Zend_Db. Please help!

I have a PosterImage class that extends Zend_Db_Table. There is also a posterImage table that has multiple columns including a MEDIUMBLOB 'image' column. (MySQL)
Whenever I use the insert method provided by Zend_Db (like the following code), the uploaded image somehow gets corrupted.

PHP Code:
$imgData addslashes (file_get_contents($_FILES['imagefile']['tmp_name']));
$imgInfo getimagesize($_FILES['imagefile']['tmp_name']);
$image addslashes (file_get_contents($_FILES['imagefile']['tmp_name']));
$imageSize $imgInfo[3];
$imageType $imgInfo['mime'];
$poster $newPoster->id;

$data = array(
    
'image' => $image,
    
'imageSize' => $imageSize,
    
'imageType' => $imageType,
    
'poster' => $poster
);
$posterImage = new PosterImage();
$posterImage->insert($data); 
However, if I use traditional database connection method to insert the image into the table (like the following code), there will be no problem retrieving the image intact.
PHP Code:
$imgData addslashes (file_get_contents($_FILES['imagefile']['tmp_name']));
$imgInfo getimagesize($_FILES['imagefile']['tmp_name']);
$image addslashes (file_get_contents($_FILES['imagefile']['tmp_name']));
$imageSize $imgInfo[3];
$imageType $imgInfo['mime'];
$poster $newPoster->id;

$link mysql_connect("localhost""sth""sth") or die("Could not connect: " mysql_error());
mysql_select_db("sth") or die(mysql_error());
$query "insert into posterimage (`image`,`imageSize`,`imageType`,`poster`) values ('$image','$imageSize','$imageType',$poster)";
$result mysql_query($query$link);
mysql_close($link); 
And my upload form is something like this:
PHP Code:
<form enctype="multipart/form-data" action="<?php echo $this->baseUrl ?>/index/<?php echo $this->action?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="307200" />
<input name="imagefile" type="file" />
<input type="text" name="some other fields" />
<input type="text" name="some other fields" />
<input type="text" name="some other fields" />
</form>
Is this another flaw of ZF? Or is it something that I have done wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:29 AM.