php 无法打开流:无效的参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2410354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:21:42  来源:igfitidea点击:

failed to open stream: Invalid argument

php

提问by Martin Wickman

In this code :

在这段代码中:

$path = "C:\NucServ\www\vv\static\arrays\news.php";
  $fp = fopen($path, "w");
  if(fwrite($fp=fopen($path,"w"),$text))
  {
    echo "ok";
  }
  fclose($fp);

I have this error message:

我有这个错误信息:

failed to open stream: Invalid argument

What is wrong in my code?

我的代码有什么问题?

回答by Martin Wickman

Your backslashes is converted into special chars by PHP. For instance, ...arrays\news.phpgets turned into

PHP 将您的反斜杠转换为特殊字符。例如,...arrays\news.php变成

   ...arrays
   ews.php

You should escape them like this:

你应该像这样逃避他们:

$path = "C:\NucServ\www\vv\static\arrays\news.php"; 

Or use singles, like this:

或者使用单打,像这样:

$path = 'C:\NucServ\www\vv\static\arrays\news.php'; 

Also, your ifis messed up. You shouldn't fopenthe file again. Just use your $fpwhich you already have.

另外,你的情况if很糟糕。你不应该fopen再次文件。只需使用您$fp已经拥有的。

回答by user7609550

  1. path error:

    $path = 'C:/NucServ/www/vv/static/arrays/news.php'; 
    
  2. file lock:

    user file_get_contents replace fopen
    
  1. 路径错误:

    $path = 'C:/NucServ/www/vv/static/arrays/news.php'; 
    
  2. 文件锁:

    user file_get_contents replace fopen