I want to store a audio file in mysql
database. I am using LONGBLOB
to store the base64
encoded string of this audio file. but just as i perform my query, i am getting this warning with no inserting on the database:
Warning: mysql_query() [function.mysql-query]: MySQL server has gone away
When i upload any image file, i am getting no error and the code works fine. this happens when i upload video and audio file. below in the code i am using:
<?php
include 'database_handler.php';
if(isset($_FILES['fileToUpload']['name'])){
echo "uploading. . .";
$file = rand(0, 10000000).$_FILES['fileToUpload']['name'];
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file)) {
if($fp = fopen($file,"rb", 0))
{
$picture = fread($fp,filesize($file));
fclose($fp);
$base64 = base64_encode($picture);
//echo $base64;
$db = new Database();
$db->test($base64);
}
}
}
?>
<form action="test.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
Here is the function code that i am calling:
function test($base64String){
if (mysql_query("update users set attribute1='$base64String' where id = '83'")){
echo "success";
}else{
mysql_error();
}
}
thanks