1

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:

<td class="crmf-custom_277_7">
      <a href="/civicrm/file?reset=1&amp;id=26&amp;eid=2&amp;fcs=ec389ea37b95642675519d22c181498543740964824c3dbb9cb80c2c483e714b_1574332030_168" class="crm-image-popup" title="carmstrong.jpg"></a>
</td>

When i click on it, the file is being downloaded as a corrupted image file.

Image of the how it appears in the UI:

7
  • It seems to work ok on 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?
    – Demerit
    Nov 21, 2019 at 14:12
  • @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.
    – Moe
    Nov 21, 2019 at 14:37
  • When you download the file, can you open the file with a text editor - what text is inside the file?
    – Demerit
    Nov 21, 2019 at 14:40
  • 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àƒÇÄÆáä.@
    – Moe
    Nov 21, 2019 at 14:49
  • Interesting the filename in the screenshot is a .jpg but the actual file is a .png? That shouldn't matter too much though.
    – Demerit
    Nov 21, 2019 at 14:56

1 Answer 1

2

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.

6
  • 1
    Thanks for your detailed response, i will try this and get back to you!
    – Moe
    Nov 28, 2019 at 9:14
  • 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.
    – Moe
    Dec 10, 2019 at 15:28
  • 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.
    – Jade
    Dec 10, 2019 at 16:13
  • 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.
    – Moe
    Dec 11, 2019 at 14:22
  • 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.
    – Moe
    Dec 11, 2019 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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