I encountered the issue with getting PHP notices all over the place when dealing with images/files, with enabled File Entity module. I've finally traced the issue to File Entity, having spent several hours trying to understand what is causing this.

The notices thrown are the following (usually getting 4 of them in a bunch):
Notice: Array to string conversion in drupal_send_headers() (line 1221 of ...\includes\bootstrap.inc).

To reproduce it I take the following steps:

  1. Install fresh Drupal 7.26
  2. Add an image field (private storage) to a content type, let's say to Article
  3. Create an article node, attach an image to it and save the node - everything works fine

Then install File Entity module, and that notice starts appearing, for example when you remove the image file from that field, save the node, then attach a new image to the node.

The notice gets thrown even without Media module, and File Entity is interfering somehow with the core functionality's dealing with files.
I set up the priority of this issue to major as in spite of being a notice, it's affecting http headers formation that may have further unpleasant consequences.

Comments

almc’s picture

Issue summary: View changes
Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

I haven't heard any reports of this sort of behavior with private files and File entity. Could you potentially help run a backtrace where the error is happening so we can see what code is causing it?

almc’s picture

I've tried backtracing however haven't got clear on the results as not having enough understanding of the header formation process in Drupal. The setup for this test case is very quick though, requiring fresh installation of Drupal 7.26 and the latest dev of File Entity, took me ~ 20 minutes after I finally suspected that the issue might be with File Entity. No special configuration settings, just proper permissions set and private uploading path for the image field.

I've encountered this issue in another environment, switching between a view with images and node entry form. Then decided to reproduce it on the minimal configuration I described above.

mariancalinro’s picture

Status: Postponed (maintainer needs more info) » Active

I'be also run into this also. The problem only shows itself when using private files. The reason is that both the core file module, and file_entity module call the function file_get_content_headers in their implementation of hook_file_download, and that image_style_deliver invokes the hook by calling module_invoke_all, which in turn uses array_merge_recursive for merging the results. From the php page for array_merge_recursive:

If, however, the arrays have the same numeric key, the later value will not overwrite the original value, but will be appended.

Thus, the string values turn to arrays, and warnings pop up, and headers are probably not sent.

There is an issue for core, that attempts to fix this by not calling module_invoke_all, and merging the results manually, thus preventing this issue from happening.

Please test the patch from there, I will too, and if it's ok, let's mark it as RTBC.

almc’s picture

Thank you for the clue Calin, the core patch worked for me too and the issue looks pinpointed neatly, I've also commented in the thread you referred.

Dave Reid’s picture

Title: Incorrect dealing with http headers: Array to string conversion in drupal_send_headers() (line 1221 of ...\includes\bootstrap.inc) » Workaround for image_style_deliver() doesn't handle duplicate headers
Related issues: +#1891228: image_style_deliver can create invalid headers

Yes we should definitely mark this as a duplicate of that core issue. It should be getting headers always the same way, and it's the fix we need. I'll leave this open if we can figure out a work-around until that core patch is applied, but right now, I don't see one.

almc’s picture

Thanks Dave, I agree - looks like using the core patch could be a way to go meanwhile.

hgoto’s picture

@Dave Reid thank you for the related issue.

I'm not sure but it may be OK to close this issue since #1891228: image_style_deliver can create invalid headers was fixed and committed :)