Forum Moderators: coopster
I've to write a swf file to mysql to a longblob field. The code to read file and write to table is below.
function asc2hex ($temp) {
$len = strlen($temp);
for ($i=0; $i<$len; $i++) $data.=sprintf("%02x",ord(substr($temp,$i,1)));
return $data;
}
$dosya = "video.swf";
$data = fread(fopen($dosya, 'rb'), filesize($dosya));
$data = asc2hex($data);
mysql_query("INSERT INTO tbl_swf(mov) VALUES '$data')");
Original file size is 1.580.894 bytes and the size after asc2hex() function is 3.161.788 bytes. After running script nothing changes in table.
As well, i can write a file that has only 15K size to table.
I though LONGBLOB types limit is 4MB, why can't i write a 3 MB file.
But I don't think your issue is with the MySQL blob type column. If you try to insert data that is too long for the column type, MySQL should truncate the data, not refuse to insert it at all.
It seems more likely to look into stuff like upload_max_filesize in your php.ini, or similar limitations on your server. What kind of error checking are you doing?
[edited]
Try adding in some error checking in appropriate places, like:
if (!file_exists($temp)) die("The file, $temp, does not exist"));
if (!$data) die("\$data is empty"));
elseif (strlen($data) > 4294967300) die("\$data will be truncated"));
if (!mysql_query("INSERT INTO tbl_swf(mov) VALUES ('$data')"))
die("The query failed: ".mysql_error()); [/edited]