0

We have set up a private file system on a website based on drupal's guidelines. We are using Drupal 8.

We have setup the private file directory outsite of /var/www at /var/privatefiles. When downloading certain types of files - specifically docx - files are being corrupted. pdfs and other common types seem to be working fine.

File upload is working correctly as I am able to scp the files directly from the server and they are intact.

Additionally, on a test server made from a copy of the server we set up the private files inside the siteroot and that works without problem. This solution is not ideal however as we do not want the files to be accessible directly from the web.

I cannot find anything that discusses this issue, surely I am not the first person to set up a private directory this way and have docx files break?

UPDATE:

Further testing indicates that what is occurring is that drupal or php are adding 3 newline 0a characters to the start of every file served from the private file system. It has np effect on some formats but all MS files - docx,xlsx etc - are broken.

How do I fix this?

  • 1
    How big are your files and how much memory does your PHP has on the server? Did you get any errors logged to PHP's error log when downloading the files? Private files are served using PHP. So the culprit may be your PHP configuration (memory_limit, base path, ...). Make sure it doesn't report any errors and/or report back what you find investigating it. – Mario Steinitz Jan 23 '18 at 23:28
  • my test file is 139 KB on disk (All the other broken files are of similar size). Download is still the same size but all garbage and not retrievable by word. No php errors are being logged. php config is set to allow 8MB max file size with 24M post_max and a memory limit of 128MB – tanbog Jan 23 '18 at 23:41
  • Ok after looking more closely at a binary diff of a good and bad file I can see Drupal or php is inserting 3 chars at the start of the file.... – tanbog Jan 24 '18 at 0:02
  • I assume this is related to this issue drupal.stackexchange.com/questions/240016/… however I do not know how to force php NOT to do this... – tanbog Jan 24 '18 at 0:14
0

We have finally solved the issue and in case it is of use will put the answer here.

Based on this php issue we realised the issue could be a closing php tag somewhere else on the site.

In the end we found three small modules - one animated a set of banner images on the site; one made some api calls for a search feature; and another created some custom blocks from an external api call.

Each of these had ?> at the end of their .module files. Removing them fixed the problem.

Why this problem went on to affect all files served I do not know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.