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?