jasmine
jasmine

Reputation:

failed to open stream: Invalid argument

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?

Upvotes: 8

Views: 44657

Answers (2)

user7609550
user7609550

Reputation: 1

  1. path error:

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

    user file_get_contents replace fopen
    

Upvotes: -2

Martin Wickman
Martin Wickman

Reputation: 19905

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

   ...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 if is messed up. You shouldn't fopen the file again. Just use your $fp which you already have.

Upvotes: 16

Related Questions