【发布时间】:2015-02-10 04:29:30
【问题描述】:
我在浏览器调试器中收到警告,但 PHP 仍然有效。为什么我会收到警告?提前致谢。
Warning: Invalid argument supplied for foreach().
HTML:
<form action="" method="post" name="savefile">
<input id="uniqueID" value="ZF4446A3GZ" name="filename" type="text">
<input name="textdata[]" type="text">
<input name="textdata[]" type="text">
<input name="textdata[]" type="text">
<input value="Done!" name="submitsave" type="submit">
</form>
PHP:
<?php
if (isset($_POST)){
foreach($_POST["textdata"] as $text){
if(!file_exists($_POST['filename'] . ".txt")){
$file = tmpfile();
}
$file = fopen($_POST['filename'] . ".txt","a+");
while(!feof($file)){
$old = $old . fgets($file);
}
file_put_contents($_POST['filename'] . ".txt", trim($text).PHP_EOL, FILE_APPEND);
fclose($file);
}
}
?>
【问题讨论】:
-
检查一下,希望对你有帮助...euperia.com/development/…和stackoverflow.com/questions/19983912/…