如何使用php中的file_put_content从不同的路径(而不是服务器默认路径)打开文件


How do i open a file from different path(not the server default path) using file_put_content in php

有没有办法从不同的路径而不是到达file_put_contents

c/programfiles/..//htdocs/test.txt使用c/test/test.txt

下面是我正在使用的代码:

$date=current_date;
$file = "test_"$date".txt";
$contents = "testtest";
file_put_contents($file, $contents);

非常感谢!

在计算机上放置文件时,可以使用相对路径或绝对路径,如下所示:

// absolute path
$file = "C:/temp/test.txt";
// relative path from C:/Program Files/wamp/htdocs/index.php
$file = "../../temp/test.txt";

这两个文件都指向同一个位置