Answers.Body: <p>Judging from the whitespace you've found in the images 'code' this is the same issue as another I've had regarding contact images not working and Mosaico images not working so I'm just going to copy most of an answer from another question that I answered which the same fix:</p>
  
  <p>So I've found this issue is due to a rogue module or theme in Drupal that has whitespace before or after the PHP opening and closing tags which is being injected into images.   </p>
  
  <p>What I suggest you do is disable all modules first (except CiviCRM and related modules as you'll need to test the images). Once you've disabled all the modules, go and check the images - they should now appear and if they do, you know you have a module with lines either before or after the PHP tags at the beginning or end of a PHP file.        </p>
  
  <p>From there, go through and activate the modules - depending on how many you have, you may want to do one or a few at a time to save a bit of time. I did 5 at a time given how many modules were on the site and when I found the batch that broke the image, I just whittled it down to find the exact one.    </p>
  
  <p>Once you've found the module that breaks the images - you may need to do a bit of digging in the code to find the whitespace if you definitely need the module. It's also a good idea to inform the maintainer of the module so that they can fix it and prevent anyone else having these issues.    </p>
  
  <p>If you find that the image is still broken after you have disabled all modules, it may be the theme although this is less likely. The same goes for the themes as above.</p>
  
  <p>Hopefully this helps you out, please let me know if you have any further questions or need extra help.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-28T09:14:51.767Z
Answers.Text: Thanks for your detailed response, i will try this and get back to you!
Answers.UserDisplayName: Moe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-10T15:28:38.667Z
Answers.Text: I have tried this a few times it ends up breaking the site. To confirm the images just break on the CiviCRM site they work fine on Drupal.
Answers.UserDisplayName: Moe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-10T16:13:26.667Z
Answers.Text: Hi Mo, disabled modules shouldn't break your site. You could try disabling them one by one to see which is causing the problem. And yes, Civi images can break from a Drupal module without Drupal having any issues.
Answers.UserDisplayName: Jade
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-11T14:22:59.747Z
Answers.Text: Thanks Jade for telling me what the issue is, turns out it was a custom extension in CiviCRM i created. After i disabled it, it has worked. Issue is i am not sure how to make the extension work now. Is possible how i worded the extension? Cause even if i remove the code in the extension the file upload still doesn't work.
Answers.UserDisplayName: Moe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-11T14:43:15.137Z
Answers.Text: I renamed the extension, it doesn't make a difference. Maybe the way i have created the extension is incorrect i only have one php file and have not created any other files or folders.
Answers.UserDisplayName: Moe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-22T06:39:30.763Z
Answers.Text: Thanks for your solution Jade. My 'rogue' was a custom module my dev had created. As soon as I removed the empty line above the opening php tage the problem was solved.
Answers.UserDisplayName: Davy Ivins
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-27T14:33:29.087Z
Answers.LastActivityDate: 2019-11-27T14:33:29.087Z
Answers.UserDisplayName: Jade
Body: <p>I have a custom field "File" which for some reason is not displaying the file. However, it is being uploaded correctly. The functionality is working fine just the display looks corrupted and if i try to download it it comes up as its not supported.</p>
  
  <p>I have done the following steps:</p>
  
  <ul>
  <li>Checked the Safe File Extensions, that is configured correctly.</li>
  <li>Replaced the /CRM &amp; /templates folder.</li>
  <li>Checked the path where the files are stored (files/civicrm/custom/),
  i can view the images here and it doesn't come up as corrupted.</li>
  <li>Checked the database and it is all put correctly.</li>
  </ul>
  
  <p>The Code for the file is being displayed like this:</p>
  
  <pre><code>&lt;td class="crmf-custom_277_7"&gt;
        &lt;a href="/civicrm/file?reset=1&amp;amp;id=26&amp;amp;eid=2&amp;amp;fcs=ec389ea37b95642675519d22c181498543740964824c3dbb9cb80c2c483e714b_1574332030_168" class="crm-image-popup" title="carmstrong.jpg"&gt;&lt;/a&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>When i click on it, the file is being downloaded as a corrupted image file.</p>
  
  <p>Image of the how it appears in the UI:</p>
  
  <p><a href="https://i.sstatic.net/QWowY.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QWowY.jpg" alt=""></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-21T14:12:49.970Z
Comments.Text: It seems to work ok on https://dmaster.demo.civicrm.org. Do you have any extensions that might be interfering? If you open the corrupted file with a text editor does it have any text in it, like an html error page?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-21T14:37:40.173Z
Comments.Text: @Demerit - No errors are showing, it did work before but not sure when it stopped working. I have disabled all extensions but still not working. Very weird. Will try to fix the issue and let you guys know.
Comments.UserDisplayName: Moe
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-21T14:40:34.400Z
Comments.Text: When you download the file, can you open the file with a text editor - what text is inside the file?
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-21T14:49:01.977Z
Comments.Text: I can open it but its all gibberish inside the file. - Here you go  ‰PNG
  
     
  IHDR  '   ¤   LëŽ‚    pHYs     šœ  
  OiCCPPhotoshop ICC profile  xÚSgTSé=÷ÞôBKˆ€”KoR RB‹€‘&*! Jˆ!¡ÙQÁEEÈ ˆŽŽ€ŒQ,Š
  Øä!¢Žƒ£ˆŠÊûá{£kÖ¼÷æÍþµ×>ç¬ó³ÏÀ–H3Q5€©BàƒÇÄÆáä.@
Comments.UserDisplayName: Moe
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-21T14:56:34.833Z
Comments.Text: Interesting the filename in the screenshot is a .jpg but the actual file is a .png? That shouldn't matter too much though.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-27T14:16:32.027Z
Comments.Text: Just following onto what Demerit said - is there an empty line at the top when you open the image with a text editor or does it show the 'code' without any space beforehand?
Comments.UserDisplayName: Jade
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-27T14:22:35.393Z
Comments.Text: @Jade - Hi Jade there is seven spaces of empty lines.
Comments.UserDisplayName: Moe
Tags: <custom-fields><upload>
Title: Custom Field "File" Display Issue
ThreadText: # Custom Field "File" Display Issue
  
  (Asked by: username_0 on 2019-11-19)
  
  I have a custom field "File" which for some reason is not displaying the file. However, it is being uploaded correctly. The functionality is working fine just the display looks corrupted and if i try to download it it comes up as its not supported.
  I have done the following steps:
  
  Checked the Safe File Extensions, that is configured correctly.
  Replaced the /CRM & /templates folder.
  Checked the path where the files are stored (files/civicrm/custom/),
  i can view the images here and it doesn't come up as corrupted.
  Checked the database and it is all put correctly.
  
  The Code for the file is being displayed like this:
  
        
  
  
  When i click on it, the file is being downloaded as a corrupted image file.
  Image of the how it appears in the UI:
  
  **Tags:** custom-fields, upload
  
  > **Comments:**
  > **username_1**: It seems to work ok on https://dmaster.demo.civicrm.org. Do you have any extensions that might be interfering? If you open the corrupted file with a text editor does it have any text in it, like an html error page?  
  > **username_0**: @username_1 - No errors are showing, it did work before but not sure when it stopped working. I have disabled all extensions but still not working. Very weird. Will try to fix the issue and let you guys know.  
  > **username_1**: When you download the file, can you open the file with a text editor - what text is inside the file?  
  > **username_0**: I can open it but its all gibberish inside the file. - Here you go  ‰PNG      IHDR  '   ¤   LëŽ‚    pHYs     šœ   OiCCPPhotoshop ICC profile  xÚSgTSé=÷ÞôBKˆ€”KoR RB‹€‘&*! Jˆ!¡ÙQÁEEÈ ˆŽŽ€ŒQ,Š Øä!¢Žƒ£ˆŠÊûá{£kÖ¼÷æÍþµ×>ç¬ó³ÏÀ–H3Q5€©BàƒÇÄÆáä.@  
  > **username_1**: Interesting the filename in the screenshot is a .jpg but the actual file is a .png? That shouldn't matter too much though.  
  > **username_2**: Just following onto what username_1 said - is there an empty line at the top when you open the image with a text editor or does it show the 'code' without any space beforehand?  
  > **username_0**: @username_2 - Hi username_2 there is seven spaces of empty lines.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-11-27. Score: 3 | Accepted answer
  
  Judging from the whitespace you've found in the images 'code' this is the same issue as another I've had regarding contact images not working and Mosaico images not working so I'm just going to copy most of an answer from another question that I answered which the same fix:
  
  So I've found this issue is due to a rogue module or theme in Drupal that has whitespace before or after the PHP opening and closing tags which is being injected into images.
  
  What I suggest you do is disable all modules first (except CiviCRM and related modules as you'll need to test the images). Once you've disabled all the modules, go and check the images - they should now appear and if they do, you know you have a module with lines either before or after the PHP tags at the beginning or end of a PHP file.
  
  From there, go through and activate the modules - depending on how many you have, you may want to do one or a few at a time to save a bit of time. I did 5 at a time given how many modules were on the site and when I found the batch that broke the image, I just whittled it down to find the exact one.
  
  Once you've found the module that breaks the images - you may need to do a bit of digging in the code to find the whitespace if you definitely need the module. It's also a good idea to inform the maintainer of the module so that they can fix it and prevent anyone else having these issues.
  
  If you find that the image is still broken after you have disabled all modules, it may be the theme although this is less likely. The same goes for the themes as above.
  
  Hopefully this helps you out, please let me know if you have any further questions or need extra help.
  
  > **Comments:**
  > **username_0**: Thanks for your detailed response, i will try this and get back to you!  
  > **username_0**: I have tried this a few times it ends up breaking the site. To confirm the images just break on the CiviCRM site they work fine on Drupal.  
  > **username_2**: Hi Mo, disabled modules shouldn't break your site. You could try disabling them one by one to see which is causing the problem. And yes, Civi images can break from a Drupal module without Drupal having any issues.  
  > **username_0**: Thanks username_2 for telling me what the issue is, turns out it was a custom extension in CiviCRM i created. After i disabled it, it has worked. Issue is i am not sure how to make the extension work now. Is possible how i worded the extension? Cause even if i remove the code in the extension the file upload still doesn't work.  
  > **username_0**: I renamed the extension, it doesn't make a difference. Maybe the way i have created the extension is incorrect i only have one php file and have not created any other files or folders.  
  > **username_3**: Thanks for your solution username_2. My 'rogue' was a custom module my dev had created. As soon as I removed the empty line above the opening php tage the problem was solved.  
  
  ---
  
  