0

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.";
    }
}
Community
  • 1
  • 1
S.W
  • 3
  • 2
  • `var_dump($_FILES);` – what does the `error` entry say …? – CBroe Jun 22 '15 at 19:17
  • I can't access it as the code doesn't get that far - the form is sent to `$_SERVER["PHP_SELF"]`, but the code under `if (isset($_POST['sent']))` is not run. – S.W Jun 22 '15 at 19:20
  • Can we see the code within the `if (isset($_POST['sent']))` block? – kittykittybangbang Jun 22 '15 at 19:23
  • Sure - added to the question. – S.W Jun 22 '15 at 19:27
  • Configure PHP to write errors to a logfile as well. – CBroe Jun 22 '15 at 19:29
  • Sure: done. It will be around 30 minutes until the file uploads and I will check the log. – S.W Jun 22 '15 at 19:39
  • Hang on, PHP errors were previously recorded in my Apache `ErrorLog` file - when they were triggered by bad coding. No new errors appeared in this file after uploading the file. Will declaring a specific log file do anything? The value in my `php.ini` was already `log_errors = On`. – S.W Jun 22 '15 at 19:47
  • No errors were written to the logfile. – S.W Jun 22 '15 at 20:38
  • _“even though the file is uploaded to the server”_ – how did you verify that part? – CBroe Jun 22 '15 at 20:41
  • I am using AJAX to monitor the file upload progress and the upload gets to 100% each time (I have tried to upload the file 4 times now). – S.W Jun 22 '15 at 20:46
  • Server can be configured to use Suhosin patch. Suhosin can disable binary file uploads or can evaluate a script on post upload for security reasons. You can check those links for more info; http://stackoverflow.com/a/3384079/3399234 https://suhosin.org/stories/configuration.html#suhosin-upload-disallow-binary https://suhosin.org/stories/configuration.html#suhosin-upload-remove-binary https://suhosin.org/stories/configuration.html#suhosin-upload-verification-script – Ugur Jun 22 '15 at 22:15
  • It doesn't look like it is installed - I used this code to check (negative result): `` – S.W Jun 22 '15 at 22:39
  • I've managed to get it working by uploading using [this Java Applet](http://jupload.sourceforge.net/). Someone else reported that they managed to upload the same application using the original upload method (on their 4th attempt), but after that it stopped working. – S.W Jun 23 '15 at 17:21

0 Answers0