Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP,将字符串保存为文本。(fputs)_Php_Html - Fatal编程技术网

PHP,将字符串保存为文本。(fputs)

PHP,将字符串保存为文本。(fputs),php,html,Php,Html,PHP HTML表单 <?php if ($changefile) { $savedEdit = stripslashes($_POST['filetest']); $filetochange = "../dashboard/list.ini"; $filetochangeOpen = fopen($filetochange,"w") or die ("Error editing."); fputs($filetochangeOpen,$savedEdi

PHP


HTML表单

<?php
if ($changefile) {
    $savedEdit = stripslashes($_POST['filetest']);
    $filetochange = "../dashboard/list.ini";
    $filetochangeOpen = fopen($filetochange,"w") or die ("Error editing.");
    fputs($filetochangeOpen,$savedEdit);
    fclose($filetochangeOpen) or die ("Error Closing File!");
}
?>




这里有一个页面,在文本框中显示INI文件。应该发生的是,当我单击submit按钮时,原始文件被打开,fputs使用txtbox中显示的任何内容写入原始文件。(原始文件设置为权限777)。但是,单击“提交”按钮时不会发生任何事情,我不知道我做错了什么,任何建议都会很棒。

您正在检查

<form method=post action="mmtst.php">   
    <textarea rows="40" cols="60" name="filetest">
    <?
        // Implode CSS
        $filetochange = "../dashboard/list.ini";
        print (implode("",file($filetochange)));
    ?>
    </textarea><br/><br/>
    <input type="submit" value="Save Changes" name="changefile">
</form>
您需要检查变量的$\u POST版本,就像您对“filetest”变量所做的一样,因此您应该例如

if ($changefile) {

否则,条件永远不会返回true,代码块也不会执行。问题很简单,您已禁用并尝试使用它,此设置允许PHP根据从get和POST数据接收的参数自动定义变量,但是它被认为是不安全的,并且被弃用

要访问post中传递的值以使用变量,请使用

如果您只想检查是否提交了post表单,您可以
!清空($\u POST)
并将提交按钮保留为空:

if( isset( $_POST["changefile"] ) ) {

所有与写相关的代码都在一个分支中:
如果($changefile)
,请尝试转储它,因为从外观上看:它可能是一个未定义的变量,在这种情况下,文件永远不会打开,更不用说写入了。同时签出,将
put
替换为
get
,以获取对应的读数。它不需要打开和关闭文件的额外行
if( isset( $_POST["changefile"] ) ) {
<?php //...
if( !empty($_POST) ) {
//...
?>
<input type="submit" value="Save Changes">