0

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
Pascal
  • 11
  • 2
  • 1
    You urgently need to upgrade your PHP version. The one you're using is no longer maintained and subject to a significant number of security flaws. – GordonM Apr 01 '15 at 16:22
  • @Gordon unfortunatly i have no control of that, i am creating a website but have no input on the chosen webserver; FML. However if i try this on my own webserer i get an internal server error – Pascal Apr 01 '15 at 16:26
  • 1
    If your host continues to use a PHP version that's been dead for four years then they can't be trusted to take security remotely seriously! If you can't persuade them to upgrade then I'd recommend finding a new host. – GordonM Apr 01 '15 at 16:27
  • Check your web server configration, limits on request size are applied there as well. eg: apache: http://stackoverflow.com/questions/11686288/apaches-limit-to-post-request-size – Sammitch Apr 01 '15 at 16:54

1 Answers1

0
unset($_FILES);

for check;

print_r($_FILES);
unset($_FILES);
print_r($_FILES);
Tyler2P
  • 2,324
  • 26
  • 22
  • 31