0

I wrote a file upload script via PHP and now i have a problem that i can't upload bigger files around 8-10 MB so do you guys have any suggestions ?

<?php
  ini_set('post_max_size', '8128M');
  ini_set('upload_max_filesize', '8128M');
  header("Content-Type: text/plain");
  $key = "M8hqvvaCbMGXP4GycfDNc6CUckYdETdPEkcdKu9QaUEM52jCZnrnrKkh8B9hVZGN";
  $uploadhost = "https://i.sandrotracker.biz/";
  $foldername = "../";
  if ($_SERVER["REQUEST_URI"] == "/robot.txt") { die("User-agent:   *\nDisallow: /"); }
  if (isset($_POST['k'])) {
if ($_POST['k'] == $key) {
    $target = getcwd() . "/" . $foldername . "/" . basename(basename($_FILES['d']['name']));
    if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) {
        $md5 = md5(microtime(true) . md5_file(getcwd() . "/" . $foldername . "/" . basename($_FILES['d']['name'])));
        rename(getcwd() . "/" . $foldername . "/" . basename($_FILES['d']
['name']), getcwd() . "/" . $foldername . "/" . $md5 . "." . 
end(explode(".", 
  $_FILES["d"]["name"])));
        echo $uploadhost . $md5 . "." . end(explode(".", $_FILES["d"]
       ["name"]));
        exit;
    } else {
      print_r($_FILES);
      exit;
    }
}
} 
echo "invalid_request";
?> 
lotfio
  • 1,916
  • 2
  • 18
  • 34
Sandro
  • 1
  • 2

1 Answers1

0

The problem is that 8128M (8,522,825,728 bytes) exceeds the 32-bit integer limit (2,147,483,647). See https://en.wikipedia.org/wiki/2,147,483,647 for a basic explanation.

You can solve this in one of two ways:

  1. Move to a 64-bit php setup.
  2. If you don't need uploads bigger than about 2GB, change:

ini_set('post_max_size', '8128M');
ini_set('upload_max_filesize', '8128M');

to:

ini_set('post_max_size', '2147483647');
ini_set('upload_max_filesize', '2147483647');
Ben Shoval
  • 1,732
  • 1
  • 15
  • 20