表格占位符只需一次PHP代码

时间:2016-08-22 08:30:22

标签: php

当第一次用户上传非jpeg / gif文件或大于2mb时,Form Placeholder正确获取php值,但第二次表单为空,用户需要重新输入。以下代码有什么问题:

<form method="post" id="comment" name="comment" action=""enctype="multipart/form-data">
  <textarea id="readerInput" name="readerInput" maxlength='950' placeholder="<?php echo $message ?>"></textarea>
  </form>



<?php
      $message = 'Your Comment';
      $name = 'Your Name';
      $email = 'Your eMail';

      if(isset($_POST['submit'])){
      $name = $_POST['name'];
        $message = $_POST['readerInput'];
        $email = $_POST['email'];

      if(is_uploaded_file($_FILES['image']['tmp_name'])){
            $tmp_image = $_FILES['image']['size'];
            $finfo = new finfo(FILEINFO_MIME_TYPE);
                    $file = $finfo->file($_FILES['image']['tmp_name']); 

      if($file!=='image/jpeg' && $file !=='image/gif' || $tmp_image > 1024*1024*2)
      { 
        echo '<script> alert("Your Image should be in jpg/gif format ?")</script>';             

                    }

由于

0 个答案:

没有答案