So I made a php file to upload files. This is the code.
HTML:
<html>
<head></head>
<body>
<form method="post" action="" enctype="multipart/form-data">
Upload File:
<input type="file" name="upload" /><br>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
PHP:
<?php
include("config.php");
if(isset($_POST['submit']) )
{
if ($_FILES['upload']['size'] != 0 ){
$filename = $con->real_escape_string($_FILES['upload']['name']);
$filedata= $con->real_escape_string(file_get_contents($_FILES['upload']['tmp_name']));
$filetype = $con->real_escape_string($_FILES['upload']['type']);
$filesize = intval($_FILES['upload']['size']);
$query = "INSERT INTO contracts(`filename`,`filedata`, `filetype`,`filesize`) VALUES ('$filename','$filedata','$filetype','$filesize')" ;
if ($con->query($query) == TRUE) {
echo "<br><br> New record created successfully";
}
else
{
echo "Error:<br>" . $con->error;
}
} else {
$filename = $con->real_escape_string($_FILES['upload']['name']);
$filetype = $con->real_escape_string($_FILES['upload']['type']);
$filesize = intval($_FILES['upload']['size']);
$query = "INSERT INTO contracts(`filename`, `filetype`,`filesize`) VALUES ('$filename','$filetype','$filesize')" ;
if ($con->query($query) == TRUE) {
echo "<br><br> New record created successfully";
} else {
echo "Error:<br>" . $con->error;
}
}
$con->close();
}
?>
But it shows the warning like this.
Warning: mysqli::query(): MySQL server has gone away in C:\xampp\htdocs\contractdb\filetest.php on line 29
Warning: mysqli::query(): Error reading result set's header in C:\xampp\htdocs\contractdb\filetest.php on line 29
Error:
MySQL server has gone away
Even though I have modify the php.ini file and restarted apache. This is what I have edited in the php.ini file. I only edited this three things only.
memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M
I try to upload the file only above 1MB and it still doesn't work. I want to upload large files. What did I do wrong to get the warning message?