无法打开流:HTTP 包装器不支持可写连接

2022-08-30 08:15:03

我已经将我的本地主机文件上传到我的网站,但它显示我这个错误:-

: [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文件夹。


答案 1

而不是这样做,你需要使用服务器路径(例如 )。file_put_contents(***WebSiteURL***...)/cache/lang/file.php/home/content/site/folders/filename.php

您不能打开文件并期望它被写入。相反,您需要使用本地路径打开它。HTTP


答案 2

你可以使用 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);
    }

推荐