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

无法打开流:没有这样的目录文件... 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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况