web-dev-qa-db-ja.com

ストリームを開けませんでした:HTTPラッパーは書き込み可能な接続をサポートしていません

LocalhostファイルをWebサイトにアップロードしましたが、次のエラーが表示されます。

: [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

コンテンツがキャッシュフォルダーのファイルに保存され、Webサーバーにファイルをアップロードすると、キャッシュされたlocalhostフォルダーにアクセスしようと個人的に感じるもの。

71

file_put_contents(***WebSiteURL***...)を実行する代わりに、/cache/lang/file.phpへのサーバーパスを使用する必要があります(例:/home/content/site/folders/filename.php)。

HTTPを介してファイルを開くことはできません。代わりに、ローカルパスを使用して開く必要があります。

146
drew010

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);
    }
13
The Bumpaster

このコードがあなたを助けますように。私の場合はうまくいきます。

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