programing

스트림을 열지 못했습니다.HTTP 래퍼에서는 쓰기 가능한 연결이 지원되지 않습니다.

sourcetip 2022. 10. 18. 22:19
반응형

스트림을 열지 못했습니다.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

개인적으로 콘텐츠가 캐시 폴더의 파일에 저장되고 웹 서버에 파일을 업로드 했을 때 캐시된 localhost 폴더에 액세스하려고 합니다.

하는 대신에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);
    }

웹 주소를 사용하기 때문에 http를 사용하여 데이터를 쓸 수 없습니다.파일을 업로드하거나 데이터를 저장하거나 이와 같은 작업을 위해 http:// 또는 https://를 사용하지 마십시오.$_SERVER["를 사용하는 대신HTTP_REFERER"]는 $_SERVER["DOCUMENT_ROOT"]를 사용합니다.다음은 예를 제시하겠습니다.

틀렸다:

move_uploaded_file($_FILES["File"]["tmp_name"],$_SERVER["HTTP_REFERER"].'/uploads/images/1.jpg')

정답:

move_uploaded_file($_FILES["File"]["tmp_name"],$_SERVER["DOCUMENT_ROOT"].'/uploads/images/1.jpg')

이 코드가 도움이 되길 바랍니다.내 경우에는 효과가 있다.

$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

반응형