duansaoguan7955
2014-06-15 18:40
浏览 100
已采纳

无法打开流:没有这样的目录文件... PHP fopen

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.

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

Does anyone have an idea on whats going on and how I can fix it?

图片转代码服务由CSDN问答提供 功能建议

这是我的代码

  include'connection.php'  ; 
setcookie('username',$ name,time()+ 86400,“/”); 
echo $ _COOKIE ['username']; 
 $ my_file ='/../../users/'.$  name。“/ index.php”; 
 $ handle = fopen($ my_file,'w')或die('无法打开文件:'。$ my_file); 
   
 \  n 

代码运行时我希望它创建一个目录为 /../../ users / [username] 的文件,其中存储 [username] $ name 变量中。 当我运行我的代码时,它只是给我一个糟糕的错误,它不会在上面的第6行之后运行任何代码。

它不会创建文件,错误是.. 。

警告:fopen(/../../ users / codemaster7 / index.php)[function.fopen]:无法打开流:没有这样的文件 或第107行/nfs/c02/h10/mnt/45563/domains/pizzascripters.com/html/projects/nik/Champion/register/index.php中的目录 无法打开文件:/../../users /codemaster7/index.php

nn

是否有人知道最新情况以及我如何解决这个问题?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanba3707 2014-06-15 18:57
    已采纳
    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.

    打赏 评论
  • duannian3494 2014-06-15 18:52

    fopen can only create a file at the specified path but it cannot create any directories. You will have to use something like mkdir to create a new directory before you call fopen.

    打赏 评论
  • doudg60800 2017-08-17 10:11

    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 upload but it should be uploads as 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
    
    打赏 评论

相关推荐 更多相似问题