Solved: Emoncms Backup module - PHP upload failing with files larger than 21Mb :-/

We're all ready to launch the final version of the new emonSD Emoncms Raspberry Pi image. However there is one little issue I would really like to fix, I've been struggling with this one for a few weeks now and making no progress :-/ 

The Emoncms Backup  module allows easy data migration from one emonBase / emonPi Emoncms install to another via the web-interface. Data is compressed into a tar.gz that can then be downloaded via web-browser and then uploaded via-browser into the new emonBase/ emonPi Emoncms. When uploading via php upload any tar.gz file larger than 21Mb fails, all smaller files 21Mb and below work fine. 

I have set in php.ini (attached) 

post_max_size = 200M
upload_max_filesize = 200M

​The php upload code we are using is:

 if ($route->action == "upload") {
        // These need to be set in php.ini
        // ini_set('upload_max_filesize', '200M');
        // ini_set('post_max_size', '200M');
        $uploadOk = 1;
        $target_path = "/home/pi/data/uploads/";
        $target_path = $target_path . basename( $_FILES['file']['name']);
        
        $imageFileType = pathinfo($target_path,PATHINFO_EXTENSION);
        
        // Allow certain file formats
        if($imageFileType != "gz")
        {
            $result="Sorry, only .tar.gz files are allowed.";
            $uploadOk = 0;
        }
        if ((move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) && ($uploadOk == 1)) {
            $fh = @fopen($import_flag,"w");
            if (!$fh) {
                $result = "ERROR: Can't write the flag $import_flag.";
            } else {
                fwrite($fh,"$import_script>$import_logfile");
                $result = "Backup flag set";
            }
            @fclose($fh);
            header('Location: '.$path.'backup');
        } else {
            $result = "Sorry, there was an error uploading the file";
        }
    }
    return array('content'=>$result);
}

https://github.com/emoncms/backup/blob/master/backup/backup_controller.p...

Any idea why PHP upload upload could be failing at 21Mb? I have attached output of php info. 

There is plenty of space left on the disk in the ~/data partition

 

Robert Wall's picture

Re: Solved: Emoncms Backup module - PHP upload failing with files larger than 21Mb :-/

I've not looked at the attachments, but a thought: If you haven't found the problem in PHP, should you be looking further back - at the server's (Apache) configuration rather than at PHP? As a workaround, can you split the file at source and reassemble it on arrival?

glyn.hudson's picture

Re: Solved: Emoncms Backup module - PHP upload failing with files larger than 21Mb :-/

Yes I've looked at the Apache config and nothing jumps out that could be the cause of uploads failing. 

As a last resort we could give up and use a dedicated java script based upload tool such as  

http://www.plupload.com/

https://github.com/moxiecode/plupload

glyn.hudson's picture

Re: Solved: Emoncms Backup module - PHP upload failing with files larger than 21Mb :-/

Doh! Issue has been solved: there was a cheeky line which must have sneaked in from the PHP upload example we followed:

<input type="hidden" name="MAX_FILE_SIZE" value="20971520" />

https://github.com/emoncms/backup/commit/32aecbca07ec2f3c6bf963fe6a3cdbc...

Robert Wall's picture

Re: Solved: Emoncms Backup module - PHP upload failing with files larger than 21Mb :-/

You must watch these little points   

And there was I, thinking I too had hit the same problem last night when downloading backups from a Wordpress site that I manage. The tools within Updraft Plus (presumably PHP) kept failing part way through a 400 MB file, Filezilla did it first time and faster.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.