PHP and Apache not uploading and processing large files

960 Views Asked by At

When I try to upload a large file (it is a 65MB .exe) to my website using an HTML form and PHP the PHP code that processes the uploaded file is not called even though the file is uploaded to the server, when I upload a smaller file it processed normally. No errors are logged in my Apache ErrorLog file.

I have changed the following entries in my php.ini file (as recommended here, here and here) and verified that the new values are loaded correctly using phpinfo() (after re-staring Apache and rebooting the server), however the problem still persists:

memory_limit = -1
upload_max_filesize = 100M
post_max_size = 150M
max_input_time = 10800
max_execution_time = 10800

I have also tried setting these values in my .htaccess file as well (AllowOverride AuthConfig FileInfo Indexes Limit Options=All,MultiViews is set under <Directory />and <Directory /var/www/> in the apache2.conf file) with the same result:

php_value memory_limit -1
php_value upload_max_filesize 100M
php_value post_max_size 150M
php_value max_input_time 10800
php_value max_execution_time 10800

The max_input_time and max_execution_time options are much higher than the time it actually takes to upload the file (30 minutes).

I am running PHP Version 5.5.9 and Apache version 2.4.7 on a server with Ubuntu 14.04 installed.

Code that should process the uploaded file:

    if (isset($_POST['sent']))
{
    $_SESSION['successfulupload']=0.1;
    $version=isset($_POST['version']) ? $_POST['version'] : '';
    $required=isset($_POST['required']) ? $_POST['required'] : '';
    $changelog=nl2br(isset($_POST['changelog']) ? $_POST['changelog'] : '');
    date_default_timezone_set('UTC');
    $date=date("d/m/y"); 
    $public=isset($_POST['public']) ? $_POST['public'] : '';
    if ($_FILES["program"]["error"]== UPLOAD_ERR_OK)
    {
        $_SESSION['successfulupload']=0.2;
        if ($_FILES["program"]["size"]>0)
        {
            $_SESSION['successfulupload']=0.3;
            $originalname = $_FILES["program"]["name"];
            $fileformat = $ext = end((explode(".", $originalname)));
            $tmp_name = $_FILES["program"]["tmp_name"];
            $name = "vStrips Installer Version " . $version . "." . $fileformat;
            if (move_uploaded_file($tmp_name, $_SERVER["DOCUMENT_ROOT"] . "/programs/" . $name))
            {
                $_SESSION['successfulupload']=0.4;
                $link="/programs/" . $name;
                $mysql_host = "xxxxx";
                $mysql_database = "vstrips_root";
                $mysql_user = "vstrips_root";
                $mysql_password = "xxxxx";
                $con=mysqli_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database);
                if (mysqli_connect_errno())
                {
                    $_SESSION['error']="Error: Failed to connect to MySQL database.";
                    die("");
                }
                $_SESSION['successfulupload']=0.5;
                $query="INSERT INTO downloads (version, date, required, changelog, link, public)
                        VALUES ('$version', '$date', '$required', '$changelog', '$link', '$public')";
                if (mysqli_query($con, $query))
                {
                    $_SESSION['successfulupload']=1;
                    echo "vStrips uploaded to website.";
                }
                else
                {
                    $_SESSION['error']="Error: " . mysqli_error($con);
                }
            }
            else
            {
                $_SESSION['error']="Error! Failed to move file from temp location.";
            }
        }
        else
        {
            $_SESSION['error']="Error! File has no content.";
        }
    }
    else
    {
        $_SESSION['error']="Error! Failed to upload file.";
    }
}
0

There are 0 best solutions below