简体   繁体   English

file_put_content 表现出奇怪的缩放行为

[英]file_put_content exhibits weird scaling behaviour

My task is to put data from a form with 24 input fields into a txt file.我的任务是将具有 24 个输入字段的表单中的数据放入一个 txt 文件中。 Not very adapt at PHP coding I got a few snippets of code from the web, the file_put_content snippet from an example with 2 input fields.不太适应 PHP 编码 我从网上得到了一些代码片段, file_put_content片段来自一个带有 2 个输入字段的示例。 It worked (=it wrote data to file and showed the 'thank_you'-page).它有效(=它将数据写入文件并显示“thank_you”页面)。 I added another field - it worked.我添加了另一个字段 - 它起作用了。 Ok, so now I added all my fields - it did not write to file and produced a blank white page.好的,现在我添加了所有字段 - 它没有写入文件并生成一个空白的白页。

I went back to the 3 fields version, and started adding fields 1 by 1. When it stopped working at 8 fields, I introduced a 2. isset(POST[]) element.我回到了 3 字段版本,并开始 1 乘 1 添加字段。当它在 8 个字段停止工作时,我引入了isset(POST[])元素。 That way I could add another 6 fields, and it worked.这样我就可以再添加 6 个字段,并且它起作用了。 (In between I separately saved the code when it successfully printed data from 11 fields to my file). (在此期间,当它成功地将 11 个字段中的数据打印到我的文件时,我单独保存了代码)。 When on the 7th field it again produced a blank page and did not save to file, I removed tha last addition - and to my BIG SURPRISE the very code that had worked before I added the last one didn't work any more?!当在第 7 场它再次产生一个空白页并且没有保存到文件时,我删除了最后一个添加 - 令我大吃一惊的是,在我添加最后一个之前工作的代码不再工作了?! I continued to remove element by element - it didn't work anymore?!我继续逐个删除元素 - 它不再起作用了?! So I reverted to the saved version of the code - and it still does not work.所以我恢复到保存的代码版本 - 但它仍然不起作用。

So I went over every single letter, sign and number - all to no avail.所以我检查了每一个字母、符号和数字——都无济于事。 Even though I havent changed anything in the html form, I ched this too, because everything points to a problem in the form that points to my php file.即使我没有更改 html 表单中的任何内容,我也更改了此内容,因为所有内容都指向指向我的 php 文件的表单中的问题。 All in vain.一切都是徒劳。 I am aware that it has to be something I did and now overlook - please point out to me where my mistake lies.我知道这一定是我做过但现在忽略的事情 - 请向我指出我的错误所在。

This is the version that worked 2 days ago, and I saved it before expanding:这是2天前有效的版本,我在展开之前保存了它:

<?php
function resetForm($form) {
$form.find('input:text, input:password, input:file, select, textarea').val('');
$form.find('input:radio, input:checkbox')
     .removeAttr('checked').removeAttr('selected');
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

if(isset($_POST['q01' | 'q02' | 'q03' | 'q04' | 'q05' | 'q06' | 'q07']) &&  isset($_POST['q08' | 'q09' | 'q99' | 'q98'])) {
    $data = $_POST['q01'] . '#' . $_POST['q02'] . '#' . $_POST['q03'] . '#' . $_POST['q04'] . '#' . $_POST['q05'] . '#' . $_POST['q06'] . '#' . $_POST['q07'] . '#' . $_POST['q08'] . '#' . $_POST['q09'] . '#' . $_POST['q99'] . '#' . $_POST['q98'] . "\n";
    $ret = file_put_contents('data/data.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        die('There was an error writing this file');
    }
    else {
        header('Location:danke.html');
    }
 exit (0);
} 
?>

Just to make sure I will also post the relevant lines of the form:只是为了确保我也会发布表格的相关行:

<form id="umfrage" class="appnitro" method="post" action="data2text.php"  accept-charset="UTF-8">

 <input id="saveForm" class="button_text" type="submit" name="submit" value="Fertig!" />

your resetForm function does not seem to be PHP.您的resetForm函数似乎不是 PHP。

isset($_POST['q01' | 'q02' | 'q03' | 'q04' | 'q05' | 'q06' | 'q07'])

what are you expecting this to do?你期待这个做什么? this does binary operations on string... This is not how you check array key availability.这对字符串进行二进制操作......这不是您检查数组密钥可用性的方式。 you should check each key individually:您应该单独检查每个键:

if (isset($_POST['q01']) || isset($_POST['q02']) .....) {

note the double pipes !注意双管

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM