free2besilly2000 Posted April 12, 2009 Share Posted April 12, 2009 Hello, There are uploaded attachments in a mysql database that are stored in two tables that have a one to many relationship. The second table is the one that actually stores the data as base64 encoded into a mediumtext field. Problem is that when the data is stored in more than one row, I have to loop through to get all the data. When I base64_decode it, no matter how long the concatenated string is, it cuts it off at 2800. So, for example, I have an image that has its data stored in 4 rows. Each data column is 3785 until the last one. When I strlen($total) I get 10,105 but when I strlen(base64_decode($total)), it chops it to 2800. When I try to look at the image via echo in IE, I only see part of the top. The smaller files stored in one row that are 2800 or less, I can see the entire image. I'm focusing on the images types for now. Any ideas? <?php $ID = $_GET['id']; $db = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); mysql_select_db("bugs",$db); $sql = "SELECT s.file_name, s.size_bytes, s.content_type "; $sql .="FROM sys_attachment s WHERE s.sys_id ='$ID'"; $result = @mysql_query($sql, $db); $name = @mysql_result($result, 0, "s.file_name"); $size = @mysql_result($result, 0, "s.size_bytes"); $type = @mysql_result($result, 0, "s.content_type"); $query = "SELECT a.data, a.sys_id FROM sys_attachment_doc a WHERE a.sys_attachment ='$ID' ORDER BY a.position"; $result2 = @mysql_query($query, $db); while($row = mysql_fetch_row($result2)) { $data = $row[0]; $total .=$data; } header("Content-type: $type"); header("Content-length: $size"); header("Content-Disposition: attachment; filename=$name"); header("Content-Description: PHP Generated Data"); echo base64_decode($total); mysql_close($db); ?> Link to comment https://forums.phpfreaks.com/topic/153694-problems-decoding-base64-files-stored-in-multiple-rows/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.