警告:fopen(FILE):无法打开流:CURRENT FILE中没有错误

时间:2016-06-30 20:15:17

标签: php fopen

我最近在创建一个超级简单的"管理页面时遇到了一个奇怪的错误。对于我目前正在制作的网站。由于我对此比较陌生,我遇到了很多错误,但最终修复了所有错误,除了一个。

用于创建新文件的代码部分如下所示:

$message = '"' . $file_location . $file_name . '" successfully created.';
$file = fopen($file_location . $file_name, 'w+');
if ($file) {
    fwrite($file, $file_content);
    if (fwrite($file, $file_content)) {
        fclose($file);
    }
    else {
        $message = 'ERROR : File contents could not be written in "' . $file_location . $file_name . '" .';
    }
}
else {
    $message = 'ERROR : Could not create "' . $file_location . $file_name . '" .';
}

例如,

  • $file_location可以是/some/path/
  • $file_name可以是file.php
  • $file_content可以是Bap a doo bap, I teach you how to buy a CANOEEE !!1

(请注意我使用WAMP并使用virtual host,因此绝对路径的使用是有意的)

由于某些原因我不明白,它给了我以下错误代码:

Warning: fopen(/path/to/new-file.php): failed to open stream: No such file or directory in C:\path\to\current-file.php on line XXX

起初,我只是认为这是我的另一个愚蠢的错误,但在多次检查代码并思考问题可能是什么之后,我无法设法弄明白。

然后我决定创建另一个只包含有问题代码的文件:

<?php
    $file_name = test.php
    $file_location = /file/location/
    file = fopen($file_location . $file_name, 'w+')
?>

这只给了我同样的错误,所以我决定将代码剥离到绝对基础,同时也使用我已经使用的include函数,只是为了检查它是否仍在工作:< / p>

<?php
    $include('file.php')
    fopen('file.php, 'w+')
?>

(请注意,我已在file.php中创建了另一个root文件

include函数DID工作时,我收到以下错误,这基本上让我放弃尝试解决问题:

Warning: fopen(file.php): failed to open stream: No error in C:\path\to\file.php on line XXX

我已经浏览了整个网络,但无法找到任何内容。这基本上使我无法使用PHP创建/修改任何文件。

1 个答案:

答案 0 :(得分:2)

我遇到了与完全相同的错误消息非常相似的问题。

 failed to open stream: No error in C:\path\to\file.php on line XXX

在我的情况下,这是因为我试图向文件发送$ _GET参数。

使用includes,您不需要发送$ _GET参数,文件不会独立执行,而是包含就像复制并粘贴到父文件中一样。我需要的所有变量都已经可用。