我正在尝试将多个文件上传到mysql数据库。
一切正常,直到大约7到8 MB。许多互联网反应说它应该与php.ini设置有关,所以我试图检查它们。我的php版本是5.2.17代码:
<?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>
我输出的ini_get是