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

前端 未结 3 1427
小蘑菇
小蘑菇 2020-11-28 07:50

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         


        
3条回答
  •  Happy的楠姐
    2020-11-28 08:34

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

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

提交回复
热议问题