无法打开流:在...中没有这样的目录文件... PHP fopen
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24232877/
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
Failed to open stream: No such file of directory in... PHP fopen
提问by Nik Olson
this is my code
这是我的代码
include 'connection.php';
setcookie('username',$name,time()+86400,"/");
echo $_COOKIE['username'];
$my_file = '/../../users/'.$name."/index.php";
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
when the code runs I want it to create a file with the directory /../../users/[username]
where [username]
is stored in the $name
variable. When I run my code it just gives me a lousy error and it doesn't run any code after line 6 from above.
代码运行时,我想它来创建一个文件与目录/../../users/[username]
,其中[username]
存储在$name
变量。当我运行我的代码时,它只会给我一个糟糕的错误,并且在上面的第 6 行之后它不会运行任何代码。
It won't create the file and the error is...
它不会创建文件,错误是...
Warning: fopen(/../../users/codemaster7/index.php) [function.fopen]: failed to open stream: No such file or directory in /nfs/c02/h10/mnt/45563/domains/pizzascripters.com/html/projects/nik/Champion/register/index.php on line 107 Cannot open file: /../../users/codemaster7/index.php
警告:fopen(/../../users/codemaster7/index.php) [function.fopen]:无法打开流:/nfs/c02/h10/mnt/45563/domains/pizzascripters 中没有这样的文件或目录.com/html/projects/nik/Champion/register/index.php 第 107 行无法打开文件:/../../users/codemaster7/index.php
Does anyone have an idea on whats going on and how I can fix it?
有没有人知道发生了什么以及我如何解决它?
采纳答案by Shyam
1 include 'connection.php';
2 setcookie('username',$name,time()+86400,"/");
3 echo $_COOKIE['username'];
4 $my_file = 'index.php';
5 $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
I update the directory of file to just a file name in line 4. if you wanna use the directory as a parameter then use the function file($myfile); which return the array of data from your file.
我将文件目录更新为第 4 行中的文件名。如果您想使用该目录作为参数,请使用函数 file($myfile); 它从您的文件中返回数据数组。
回答by PowerGamer
回答by Bashir ahmad
This error often occurs when you miss or misspell something like here I did it first
当您遗漏或拼写错误时,经常会发生此错误,例如我先做的
$path = Yii::getAlias('@common') .'/upload/images/'. $model
Here the spell is uploadbut it should be uploadsas in my project it is uploads. the wrong spell gave me this error. so this often occurs when the path is unknown
这里的拼写是上传,但它应该是上传,因为在我的项目中它是上传。错误的拼写给了我这个错误。所以这通常发生在路径未知时
$path = Yii::getAlias('@common') .'/uploads/images/'. $model