fopen(),fwrite()函数在php中不起作用

时间:2018-04-18 10:46:24

标签: php scheduled-tasks fopen

以下是我的代码,

test.php的

<?php
$prefixnew = "testnew";
$file1 = fopen("testnew.txt","w");
$content_wr_g = "Test sitest"
fwrite($file1,$content_wr_g);
fclose($file1);
?>

test.bat的

@ECHO off


C:\wamp\bin\php\php5.3.13\php.exe -f  "C:\...\test.php"


popd

更新

当我直接从浏览器运行(test.php)时,它正常工作。如果我从预定的任务中运行,它就无法正常工作。

我非常清楚创建任务的任务调度程序步骤。当我运行一组更新查询或删除查询意味着,它运行良好。

当我有fopen(), fwrite()等代码时,它无效

1 个答案:

答案 0 :(得分:0)

不使用相对路径,而是使用文件的绝对路径:

$file1 = fopen(__DIR__.'/testnew.txt', 'w');

我假设您正在使用>= PHP 5.3,如果没有尝试:

$file1 = fopen(dirname(__DIR__).'/testnew.txt', 'w');