Programing

스트림을 열지 못했습니다 : HTTP 래퍼가 쓰기 가능한 연결을 지원하지 않습니다.

lottogame 2020. 10. 29. 07:44
반응형

스트림을 열지 못했습니다 : HTTP 래퍼가 쓰기 가능한 연결을 지원하지 않습니다.


내 localhost 파일을 내 웹 사이트에 업로드했지만 다음 오류가 표시됩니다.

: [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/
***Folders\FileName*** .php

개인적으로 내용이 캐시 폴더의 파일에 저장되고 파일을 웹 서버에 업로드했을 때 캐시 된 로컬 호스트 폴더에 액세스하려고 시도하는 것 같습니다.


대신 file_put_contents(***WebSiteURL***...)서버 경로 /cache/lang/file.php(예 :) 를 사용해야합니다 /home/content/site/folders/filename.php.

파일을 열어서 HTTP기록 될 것으로 기대할 수 없습니다 . 대신 로컬 경로를 사용하여 열어야합니다.


fopen () 함수를 사용할 수 있습니다.

몇 가지 예 :

$url = 'http://doman.com/path/to/file.mp4';
$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) {
      fclose($file);
    }

    if ($newf) {
      fclose($newf);
    }

이 코드가 도움이 되길 바랍니다. 제 경우에는 작동합니다.

$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);

참고 URL : https://stackoverflow.com/questions/9748076/failed-to-open-stream-http-wrapper-does-not-support-writeable-connections

반응형