Skip Navigation

[Resolved] Getting “failed to open stream” Error when trying to display images

This thread is resolved. Here is a description of the problem and solution.

Problem: Images are being rendered as garbled code on my site, and I'm seeing errors in my PHP logs:

[31-Jan-2018 15:33:57 UTC] PHP Warning:  fopen(https://mysite.com/wp-content/uploads/biz-after-biz-logo-300x200_center_center.jpg) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections in /path/to/wp-includes/class-wp-image-editor.php on line 407
[31-Jan-2018 20:36:07 UTC] PHP Warning:  fopen(https://mysite.com/wp-content/uploads/biz-after-biz-logo-960x450_center_center.jpg) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections in /path/to/wp-includes/class-wp-image-editor.php on line 407

Solution: If you are using SSL on your site and showing the site at HTTPS instead of HTTP, make sure your site URLs in Settings > General are configured to use HTTPS as well. Otherwise, you'll run into cross-protocol issues.

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 12 replies, has 2 voices.

Last updated by peterR-3 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#618125
garbled_code_screenshot.png

Hello,

In a site I built using Divi + Toolset, I use the following shortcodes to display images on various pages:

[wpv-post-featured-image size="custom" width="960" height="450" crop="true"]
[wpv-post-featured-image size="custom" width="300" height="200" crop="true" id="#_EVENTPOSTID"]

Normally to me, this appears to work fine. But I get emails from my client who say their visitors are seeing garbled text/code instead of images. You can see an example in the attached screenshot.

When looking into this, I found many errors in the site's log. They look like so...

[31-Jan-2018 15:33:57 UTC] PHP Warning:  fopen(<em><u>hidden link</u></em>) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections in /home/sdcconca/public_html/wp-includes/class-wp-image-editor.php on line 407
[31-Jan-2018 20:36:07 UTC] PHP Warning:  fopen(<em><u>hidden link</u></em>) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: HTTP wrapper does not support writeable connections in /home/sdcconca/public_html/wp-includes/class-wp-image-editor.php on line 407

... and hundreds more of the same errors with various(and the same too) image file names.

I don't know why these errors show sometimes, but not all the time. Is it something to do with the images being resized?

Any idea what's causing this?

FYI: allow_url_fopen is ON and all images are stored on the same site as the server.

Thanks

#618386

I see some information about this error on stackoverflow:
https://stackoverflow.com/questions/9748076/failed-to-open-stream-http-wrapper-does-not-support-writeable-connections
https://stackoverflow.com/questions/9818754/fopen-cant-write-with-error-http-wrapper-does-not-support-writeable-connecti

Let's try to narrow things down.
- Is this issue reproducible with only Types, Views, and Twenty Seventeen active?
- If no, reactivate your theme and plugins one by one until the conflict is revealed.
- If yes, open the browser console and copy any errors or warnings you see when the page is loaded. For example, when I go to /events now, I see several mixed content warnings in the browser. This indicates that the images are saved at HTTP URLs, but you're trying to show them on an HTTPS page:

Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
events:499 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
95498.js:2 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
(anonymous) @ 95498.js:2
i @ 95498.js:2
fireWith @ 95498.js:2
ready @ 95498.js:2
K @ 95498.js:2
95498.js:2 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
(anonymous) @ 95498.js:2
i @ 95498.js:2
fireWith @ 95498.js:2
ready @ 95498.js:2
K @ 95498.js:2
events:1 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
95498.js:2 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
clone @ 95498.js:2
(anonymous) @ 95498.js:2
(anonymous) @ 95498.js:2
map @ 95498.js:2
map @ 95498.js:2
clone @ 95498.js:2
et_define_logo_dimension @ 32b98.js:111
(anonymous) @ 32b98.js:111
dispatch @ 95498.js:2
r.handle @ 95498.js:2
95498.js:2 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
ja @ 95498.js:2
Ha @ 95498.js:2
append @ 95498.js:2
(anonymous) @ 1f61f.js:57
each @ 95498.js:2
each @ 95498.js:2
(anonymous) @ 1f61f.js:57
dispatch @ 95498.js:2
r.handle @ 95498.js:2
95498.js:2 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
ja @ 95498.js:2
Ha @ 95498.js:2
append @ 95498.js:2
(anonymous) @ 1f61f.js:57
each @ 95498.js:2
each @ 95498.js:2
(anonymous) @ 1f61f.js:57
dispatch @ 95498.js:2
r.handle @ 95498.js:2
95498.js:2 Mixed Content: The page at '<em><u>hidden link</u></em>' was loaded over HTTPS, but requested an insecure image '<em><u>hidden link</u></em>'. This content should also be served over HTTPS.
#618470

Thanks for spotting why I wasn't able to reproduce the problem, you somehow accessed the site via https instead of http. Did you type https manually? I've always accessed the site via http only, as it was meant to be viewed.

When viewing the site via http, the errors and garbled code do not show, as you can see here:

hidden link

But when viewing the same page via https, the error and garbled code appear, as you can see here:

hidden link

This appears to happen only on pages where Toolset has been used combined with accessing those pages via https. For example, these pages which don't display an image via Toolset, produce no (fopen)errors even though they are accessed via https:

hidden link
hidden link
hidden link
etc

But these pages that do include images via Toolset shortcodes do show (fopen)errors and garbled text:

hidden link
hidden link
hidden link
- any event listed at hidden link

One more observation... This site contains a business directory built with Toolset:

hidden link

Strangely enough, if I manually type the https address to a specific business(there's only one that has an image), this page does NOT produce an error even though it was built via Toolset and is being accessed via https:

hidden link

Does this page not product an error because it is a template? Do the other pages show errors because I'm using a Toolset shortcode on non-template pages?

#618512

Just an update on steps I'm taking to figure out the issue...

I tried deactivating the following plugins but it made no impact:

Divi/Extra Layout Injector
Events Manager
Regenerate Thumbnails
W3 Total Cache

I created a very basic page using the Divi Blank Page template. I only placed a little bit of text on it and the following shortcode:

[wpv-post-featured-image size="custom" width="960" height="450" crop="true"]

If you access the page via http, no errors:
hidden link

If you access the page via https, errors are produced:
hidden link

#618535
test_page_console_screenshot.png
test_page_screenshot.png

Okay, so I disabled all plugins except Toolset ones and changed the theme to Twenty Seventeen. Unfortunately this didn't appear to help at all.

As you can see in the attached images, the error still displayed when viewing the page ( hidden link ) via https but NOT via http.

When the error-test page was viewed via https, this is what appeared in the browser console (which also can be seen in one of the attached images):

main.js:320 [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See <em><u>hidden link</u></em>
loadListeners @ main.js:320
chrome.storage.local.get @ main.js:425
safeCallbackApply @ VM226 extensions::uncaught_exception_handler:27
handleResponse @ VM227 extensions::sendRequest:67
jquery-migrate.min.js?ver=1.4.1:2 JQMIGRATE: Migrate is installed, version 1.4.1
[Violation] Forced reflow while executing JavaScript took 2392ms
jquery.js?ver=1.12.4:2 [Violation] 'DOMContentLoaded' handler took 674ms
[Violation] Forced reflow while executing JavaScript took 664ms

I've since reactivated plugins and returned to the Divi theme.

#618542

Just an FYI, after doing the testing mentioned in my previous post, I looked at the error log for the site and saw 2 of these errors:

[22-Feb-2018 07:27:52 UTC] PHP Catchable fatal error:  Object of class __PHP_Incomplete_Class could not be converted to string in /home/sdcconca/public_html/wp-content/plugins/wp-views/vendor/toolset/toolset-common/toolset-forms/classes/class.types.php on line 540

I doubt this is of any importance as these errors only occurred twice in the whole error log and only during testing when I was deactivating/activating plugins and themes etc. Just posting the info here for a complete picture.

#618752

Did you type https manually?
I do not recall, but my browser always chooses HTTPS if it's available.

When the error-test page was viewed via https, this is what appeared in the browser console (which also can be seen in one of the attached images):
Those violations can be ignored for now.

As you can see in the attached images, the error still displayed when viewing the page ( <em><u>hidden link</u></em> ) via https but NOT via http.

In wp-admin, go to Settings > General and check the protocols for both of these URLs:
WordPress Address (URL)
Site Address (URL)
Let me know what you find.

#618755

Okay thanks. I believe cPanel makes https available automatically since it can now add free SSL certs. But at this time I want sites accessed via http to keep them loading quicker until I can upgrade the server. I think I can force all traffic to http via htaccess to maybe avoid these errors, but I'd rather find the root cause as one day I'll want to switch to https.

I checked the WordPress settings and both addresses are set to: hidden link

#618807

Please go to Toolset > Settings > Custom Content tab. Click "Clear cached images" and "Clear outdated cached images". Check both of the checkboxes in the images section. The image itself actually exists on the secure protocol:
hidden link

If this does not resolve the problem, I need to log in to your wp-admin area and create a clone of your site to run some more tests. If that's okay, please use the private fields here to provide login credentials.

#619500

I'm getting an error when I attempt to create a backup using the Duplicator Pro plugin:

Account out of space so purge large files or talk to your host about increasing quota.

Can you check to see how much file space you have free on this server? Is it possible to backup any irrelevant data and remove it from the server temporarily so I can create a clone?

#619512

I've removed the disk quota for that account so you should have the needed space now.

#619520

Okay I created a clone of your site and installed it locally on an HTTPS test environment with a self-signed certificate. The image loads over HTTPS without any problem for me. My local site URL uses https whereas yours uses http. I'm not able to figure out how to get around that in my local environment - I cannot access the site at HTTPS when the site URL is configured to use HTTP. So my guess is that the garbled image code is a side effect of this site configuration difference. When you're ready to migrate the entire site to https, I suggest we keep an eye out for this issue, and plan to resolve any outstanding problems with images at that time.

#625732

In the wordpress General settings, I changed the WordPress and Site addresses to https instead of http. Now when accessing pages via https there are no errors. Changing to https didn't seem to slow things down too much so I went ahead and completed the conversion. Would be nice if Toolset worked with an http/https mix but I can live with https only. Please delete private server info etc.

Thanks.