[Solved] failed to open stream: HTTP wrapper does not support writeable connections

I have uploaded my localhost files to my website but it is showing me this error:-

: [2] file_put_contents( ***WebsiteURL*** /cache/lang/ ***FileName*** .php) 
[function.file-put-contents]: failed to open stream: HTTP wrapper does 
not support writeable connections | LINE: 127 | FILE: /home/content/
***FoldersFileName*** .php

What i personally feel that the contents get saved in a file in cache folder and when i uploaded the files to my web server it is trying to access the cached localhost folder.

Solution #1:

Instead of doing file_put_contents(***WebSiteURL***...) you need to use the server path to /cache/lang/file.php (e.g. /home/content/site/folders/filename.php).

You cannot open a file over HTTP and expect it to be written. Instead you need to open it using the local path.

Respondent: drew010

Solution #2:

you could use fopen() function.

some example:

$url = '';
$destination_folder = $_SERVER['DOCUMENT_ROOT'].'/downloads/';

    $newfname = $destination_folder .'myfile.mp4'; //set your file ext

    $file = fopen ($url, "rb");

    if ($file) {
      $newf = fopen ($newfname, "a"); // to overwrite existing file

      if ($newf)
      while(!feof($file)) {
        fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );


    if ($file) {

    if ($newf) {
Respondent: The Bumpaster

Solution #3:

May this code help you. It works in my case.

$filename = "D:xampphtdocswordpress/wp-content/uploads/json/2018-10-25.json";
    $fileUrl = "http://localhost/wordpress/wp-content/uploads/json/2018-10-25.json";
        $handle = fopen( $filename, 'a' ) or die( 'Cannot open file:  ' . $fileUrl ); //implicitly creates file
        fwrite( $handle, json_encode(array()));
        fclose( $handle );
    $response = file_get_contents($filename);
    $tempArray = json_decode($response);
        $count = count($tempArray) + 1;
        $count = 1;
    $tempArray[] = array_merge(array("sn." => $count), $data);
    $jsonData = json_encode($tempArray);
    file_put_contents($filename, $jsonData);
Respondent: Birendra Maharjan

Solution #4:

it is because of using web address, You can not use http to write data. don’t use :
http:// or https:// in your location for upload files or save data or somting like that. instead of of using $_SERVER[“HTTP_REFERER”] use $_SERVER[“DOCUMENT_ROOT”].
for example :

wrong :



Respondent: user2215032

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy