我有一个filelist.txt文件,我创建了一个名为clear.php的文件来清除filelist的内容。
我在index.html中放置了一个按钮来调用clear.php来清除文件。
关于我应该用clear.php写什么样的PHP代码,有人能帮我吗?
如何编写一个按钮来调用clear.php,然后返回到index.html,显示它已被清除的结果?
发布于 2009-07-02 02:26:56
file_put_contents("filelist.txt", "");
您可以使用header()函数修改Location头部进行重定向。
发布于 2009-07-02 02:28:58
这将截断该文件:
$fh = fopen( 'filelist.txt', 'w' );
fclose($fh);
在clear.php中,使用$_SERVER['HTTP_REFERER']
值重定向到调用者页面。
发布于 2009-07-09 15:02:44
//create a file handler by opening the file
$myTextFileHandler = @fopen("filelist.txt","r+");
//truncate the file to zero
//or you could have used the write method and written nothing to it
@ftruncate($myTextFileHandler, 0);
//use location header to go back to index.html
header("Location:index.html");
我不知道你想在哪里展示结果。
https://stackoverflow.com/questions/1073609
复制