php - 无法打开流 : No such file of directory in. .. PHP fopen

标签 php file cookies directory fopen

这是我的代码

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);

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

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

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

有人知道发生了什么事以及我该如何解决它吗?

最佳答案

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);

我在第 4 行将文件目录更新为文件名。如果您想使用目录作为参数,请使用函数 file($myfile);它返回文件中的数据数组。

关于php - 无法打开流 : No such file of directory in. .. PHP fopen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24232877/

相关文章:

c - 从文件中删除字符串

php - 将涉及同名重复元素的数据发送到 SOAP API

php - 循环以垂直填充 html 表

vba - 外部文件属性未更新 - VBA

python - 在 Django 中设置多个同名的 cookie

javascript - AngularJS cookie 不起作用

java - 如何从 Java 中的 post 请求中提取 httponly cookie?

php - 如何对flv视频进行悬停预览?

php-fpm 的监控配置

c# - 使用 StreamWriter 时进程无法访问文件