Quantcast
Viewing all articles
Browse latest Browse all 9622

Re: Submissions in Moodle assignments are corrupted upon download

by Richard Flurey.  

Hi Martin,

I finally got to the bottom of the issue and figured out a workaround myself. It's nice to get to the point where you can answer your own questions. I know the problem isn't with the flavour of Linux per se (as lecturered to us by Richard) but I mentioned that we recently moved to Ubuntu 14.04 and on the latest Moodle just to see if anyone else has a similar experience with the same file corruption problem in assignments. It looks like we are not the only one!


I suspected the problem had something to do with caching and at first I thought it might be the Zend opcache. However, I turned this off during a quiet moment and restarted Apache and this made no difference. Then I had a sudden brainwave pointing me in the direction of output_buffering, a setting in php.ini which I'd left untouched.


I know in the past this setting is preferable to be turned off but what I figured about php 5.5 is that it's often set to 4096 by default. I tried turning it off and it did make some difference to the way files download from assignments. Unfortunately, it broke the forcedownload mime type functionality and loaded the files into the browser but I did notice the extra space in the front of the file header had disappeared. It might have solved the corruption issue but how to download the file? So I tried different output_buffering settings which made no difference and put it back to the default of 4096.


At this stage I reckoned it had to be enabled but there must be another way to prevent the corruption in the buffering. Now this behaviour does seem specific to the updated patch/release version of PHP 5.5.9/Apache 2.4 used within Ubuntu 14.04 since the corruption doesn't seem to occur in other PHP/Apache versions being used by other Linux distributions. After doing a bit more searching online I found the following suggestion which worked a treat when I figured where it was best placed in the Moodle code.


Find the following 2 lines in /lib/filelib.php just after (line 1977 in Moodle 2.7.1):

function readfile_allow_large($path, $filesize = -1) {
    // Automatically get size if not specified.


Add the following 2 lines directly after the lines above:

ob_clean();   // discard any data in the output buffer (if possible)
flush();      // flush headers (if possible)

Make sure you take a backup copy of the filelib.php of course and be sure to flush the opcache, or simply restart Apache if you able to. Once a new copy of filelib.php is running in the cache it's good to go. I was able to download ZIP files from the assignments and open them with no problem with no leading spaces before the 'PK' file header that previously stopped them from opening. Same applies to all the other file types that appeared corrupted because of the leading white space.


I hope this helps you and potentially others too.


Cheers,

Richard


Viewing all articles
Browse latest Browse all 9622

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>