PHP和HTML一起导致错误表单未提交

时间:2018-07-01 15:15:52

标签: php html

这是php代码,在此之下我有html代码

<?php
  if(!file_exists('post.txt')){
    echo "Post file does not exist";
    exit;
  } 
  if(!file_exists('stop_words.txt')){
    echo "Post file does not exist";
    exit;
  }
  if(!file_exists('post.txt')){
    echo "Post file does not exist";
    exit;
  }

$post = file_get_contents('post.txt');
$stop_words = file('stop_words.txt');

foreach ($stop_words as $word) {
    $word = rtrim($word);
    $post = preg_replace("/\b$word\b/i", "", $post);
}

$post = preg_replace("/\d/", "", $post);
$post = preg_replace("/[?;:!,.'\"]/", "", $post);

$output = fopen('output.txt', 'w') or
    exit("Unable to open file output.txt\n!");
fwrite($output, $post);
fclose($output);

echo 'File has been processed successfully.<br>';
?>

我的php代码到此结束,所以我将html代码放在这里,但这一起导致错误。这样,当提交下面代码中的表单时,我在'upload.php'文件中使用了if语句来检查

if (isset($_POST[submit]){die 'Submitted';} 

,但未输入此if语句。当我将代码分隔到另一个文件代码中工作并且是否执行了语句

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload File" name="submit">
</form>
</body>
</html>

这是正在提交表单的“ upload.php”文件

<?php
if(isset($_POST['submit'])){
die('Submitted');
}
$target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], 
$target_file)) 
{
  echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been 
uploaded.";
} else {
  echo "Sorry, there was an error uploading your file.";
}
?>

潜在的错误原因是什么?

0 个答案:

没有答案