i am trying to upload multiple files to a mysql database.
Everything works fine untill i surpass around 7 to 8 MB. A lot of internet reactions say it should have something to do with the php.ini settings, so i've tried to check them. My php version is 5.2.17 code below:
<?php include_once "mysql.php"; ?>
<body>
<form action="" method="post" enctype="multipart/form-data">
<label for="album">Album</label>
<input type="text" id="album" name="album" /><br>
<label for="fotos">Foto's</label>
<input type="file" id="files" name="files[]" multiple accept="image/*" />
<input type="submit" value="Upload" />
</form>
<?php
echo "<br>upload_max_filesize: ".ini_get('upload_max_filesize');
echo "<br>post_max_size: ".ini_get('post_max_size');
echo "<br>memory_limit: ".ini_get('memory_limit');
echo "<br>realpath_cache_size: ".ini_get('realpath_cache_size');
echo "<br>realpath_cache_ttl: ".ini_get('realpath_cache_ttl');
$valid_formats = array("jpg", "png", "gif", "bmp");
$max_file_size = 6291456; //6MB
$count = 0;
$mysql = new MySQL; //own class
$mysql->db_connect();
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $index => $name)
{
echo $index;
$fotos[$index]['album'] = $_POST['album'];
$fotos[$index]['name'] = $_FILES['files']['name'][$index];
$fotos[$index]['type'] = $_FILES['files']['type'][$index];
$fotos[$index]['tmp_name'] = $_FILES['files']['tmp_name'][$index];
$fotos[$index]['error'] = $_FILES['files']['error'][$index];
$fotos[$index]['size'] = intval($_FILES['files']['size'][$index]);
}
foreach ($fotos as $foto)
{
if($foto['error'] == 0)
{
if($foto['size'] < $max_file_size)
{
$fp = fopen($foto['tmp_name'], 'r');
$content = fread($fp, filesize($foto['tmp_name']));
$content = addslashes($content);
fclose($fp);
$mysql->qry("INSERT INTO albums (`album`, `type`, `name`, `img` ) VALUES ('".$foto['album']."', '".$foto['type']."', '".$foto['name']."', '".$content."')");
}
else
{
echo "File to big<br>";
echo "file: ".$foto['size']." < Max: ".$max_file_size."<br>";
}
}
else
{
echo "errorcode: ".$fotos['error'] . "<br>";
}
}
$mysql->close();
echo "<pre>";
print_r($fotos);
echo "</pre>";
}
?>
</body>
my output of ini_get is
- upload_max_filesize: 128M
- post_max_size: 128M
- memory_limit: 256M
- realpath_cache_size: 4M
- realpath_cache_ttl: 120