我想用文件名分配路径信息,文件名也存储在另一个变量中,我使用下面的代码但是它没有工作
$title = $_POST['title'];
$ext = '.txt';
$counter_name = '/counters/titles/'.$title.$ext;
我希望counter_name变量保存路径信息和文件名,然后检查文件是否存在,如果没有,创建一个新文件并将其初始化为零,这在添加路径信息之前有效但现在如果当我检查titles文件夹时,我看不到任何.txt文件
if (!file_exists($counter_name)) {
$f = fopen($counter_name, "w");
fwrite($f,"0");
fclose($f);
}
答案 0 :(得分:0)
将代码更改为现在可以使用
$title = $_POST['adtitle'];
$ext = '.txt';
if (!file_exists('counters/titles/'.$title.$ext)) {
$f = fopen('counters/titles/'.$title.$ext, "w");
fwrite($f,"0");
fclose($f);
}