File Download Problem

Permalink 1 user found helpful
I am on version 5.4.1.1 of Concrete5 and I am having a problem with the file block. When I download zip files using the file block the downloaded file cannot be opened. If I use the download link on the File Manager of the Dashboard the archive can be opened fine.

I tried to track down the issue and looked into the FileHelper but it appears to have all the headers correct for a forced download.

Anybody else have this issue?

argvader
 
tallacman replied on at Permalink Reply
tallacman
Can you post a url?

Steve
argvader replied on at Permalink Best Answer Reply
argvader
I figured out my issue.

Looking at the binary data of the zip files and extra blank line was placed as the first line. This cause the zip file to report as being corrupted.

I fixed it using two changes. First I removed the closing ?> php tag on the file helper and also issued an ob_clean and flush() before the fread in the forceDownload method.
dimunation replied on at Permalink Reply
I had a majority of downloaded files, namely every MSOffice document, showing up as gibberish when downloaded. These changes have completely fixed the problem.

Thanks!
argvader replied on at Permalink Reply
argvader
I was curious about other binary file types. Glad it helped you.
helenmarie replied on at Permalink Reply
helenmarie
I am also having problems with the file download block. The images are corrupt and wont open after download?
Which files did you edit to fix it? Thank you for any help you can give me, Helen
argvader replied on at Permalink Reply
argvader
The file i changed is file.php in the concrete/helpers directory.

This should be in your installation directory. If you performed an upgrade from a previous version you may have the newer concrete5 code in the updates directory. If that's true then you will need to edit the file.php file within the updates directory.

Ideally you should be able to put your file.php in your own helpers directory to overwrite the C5 core one but the redeclaration of the file class causes an error. So I had to change the core file. I did submit a solution to the bug tracker so it may make it into newer versions.

I guess that's a long way of saying if you update C5 again you may have to redo this change unless it makes it into the updated release.

Hope this helps you.
helenmarie replied on at Permalink Reply
helenmarie
Hello, Thank you for your reply.

Im not really up on PHP and dont know what ob_clean and flush means haha.

Im guessing it goes somewhere in here?


$buffer = '';
      $chunk = 1024*1024;
      $handle = fopen($file, 'rb');
      if ($handle === false) {
         return false;
      }
      while (!feof($handle)) {
         $buffer = fread($handle, $chunk);
         print $buffer;
      }
      fclose($handle);
      exit;      
   }


but where and how?

Thank you, Helen
argvader replied on at Permalink Reply 1 Attachment
argvader
I attached the file.php file for you. I had to attach the file as a text file.

Hope this gets you going.
helenmarie replied on at Permalink Reply
helenmarie
Oh thank you so much :-) That has worked a treat. Fab thank you