1

Whenever I run some code in PHP, I get these warnings:

Warning: fopen(extfiles/
Notice: Undefined offset: 1 in C:\filepath\file.java): failed to open stream: Invalid argument in C:\filepath\file.php on line 82 Warning: feof() expects parameter 1 to be resource, boolean given in C:\filepath\file.php on line 84
Warning: fgets() expects parameter 1 to be resource, boolean given in C:\filepath\file.php on line 87

The lines from the code:

$filenamee = $_POST["filename"];
$folder = $_POST["folder"];

$var1 = explode(".", $filenamee);
$var2 = explode(".", $folder);

$filename = "extfiles/".$var2[0]."/".$var1[0].".java";
$file = fopen($filename, "c"); // This is line 82
$lines_array = array();
while (!feof($file)) { // This is line 84


    $line = fgets($file); // This is line 87
    array_push($lines_array, $line);

}

The code needs to create and edit Java file, but the problem is that it isn't creating it. Whenever I run this code, I get the last 2 warnings lots of times...

What can I do in order to solve it?

Muntashir Akon
  • 8,740
  • 2
  • 27
  • 38
Ido
  • 171
  • 2
  • 13

1 Answers1

0

It sounds like the script can not find the file to open. extfiles/ works from the directory the php file is located in. Can we get a tree view of your dir structure? Typically you'll want to define the entire file path from the root of the drive upward.

David J Eddy
  • 1,999
  • 1
  • 19
  • 37