文件未在表单提交中发布

时间:2016-12-21 01:06:33

标签: html forms file file-upload

我有一个表单,我似乎无法弄清楚文件没有发布的原因。

看起来这应该是相当直接的,但它似乎踢了我的屁股。

我正在使用PHPmailer插件。

我收到所有其他字段,但我收到了电子邮件,但该文件从未包含在内,因为它从不发布。

表格代码。



<form id="bookrelease" name="bookrelease" method="post" enctype="multipart/form-data">
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="startdate">
        <div class='input-group date' id='datetimepicker1'>
          <input id="startdate" name="startdate" type='text' class='inputspecial form-fixed-height' placeholder="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Start Date">
          <span class="input-group-addon calendarbtn">
                                                    <span class="glyphicon glyphicon-calendar calendarbtn2"></span>
          </span>
        </div>
        <label for="startdate" id="startdateLb"><span class="error">*Start date required.</span>
        </label>
      </p>
    </div>
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="enddate">
        <div class='input-group date' id='datetimepicker2'>
          <input id="enddate" name="enddate" type='text' class='inputspecial form-fixed-height' placeholder="&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;End Date">
          <span class="input-group-addon calendarbtn">
                                                    <span class="glyphicon glyphicon-calendar calendarbtn2"></span>
          </span>
        </div>
        <label for="enddate" id="enddateLb"><span class="error">*End date required.</span>
        </label>
      </p>
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="BRauthorname">
        <input class="form-fixed-height" type="text" id="BRauthorname" name="BRauthorname" placeholder="Author Name">
        <label for="BRauthorname" id="BRauthornameLb"><span class="error">*Author name required</span>
        </label>
      </p>
    </div>
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="ABRemail">
        <input class="form-fixed-height" type="email" id="ABRemail" name="ABRemail" placeholder="Author Email">
        <label for="ABRemail" id="ABRemail-1Lb"><span class="error error1">*Email Field Required</span>
        </label>
        <label for="ABRemail" id="ABRemail-2Lb"><span class="error error2">*Email Not Valid</span>
        </label>
      </p>
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="booktitle">
        <input class="form-fixed-height" type="text" id="booktitle" name="booktitle" placeholder="Book Title">
        <label for="booktitle" id="booktitleLb"><span class="error">*Book title required</span>
        </label>
      </p>
    </div>
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="authorwebsite">
        <input class="form-fixed-height optional" type="url" id="authorwebsite" name="authorwebsite" placeholder="Author Web Site - optional">
      </p>
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="sellerssite">
        <input class="form-fixed-height" type="url" id="sellerssite" name="sellerssite" placeholder="Book Retailer's Web Address">
        <label for="sellerssite" id="sellerssiteLb"><span class="error">*Book retailer's web address required</span>
        </label>
      </p>
    </div>
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class='booktype'>
        <input class="form-fixed-height optional" type="text" id="booktype" name="booktype" placeholder="Format(s) - optional">
      </p>
    </div>
  </div>
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="genre">
        <input class="form-fixed-height optional" type="text" id="genre" name="genre" placeholder="Genre(s) - optional">
      </p>
    </div>
    <div class="col-xs-12 col-sm-12 col-m-6 col-lg-6">
      <p class="fixedheight">
        <input class="file form-fixed-height" id="BRfile" type="file" name="BRfile" data-preview-file-type="image" />
        <label for="BRfile" id="BRfileLb"><span class="error">*opps! invalid file. Only jpeg and png files accepted</span>
        </label>
      </p>
    </div>
  </div>
  <div class="text-center">
    <div id="ErrResults">
      <!-- Error Here -->
    </div>
    <div id="MainResult">
      <!-- Response Here -->
    </div>
    <a href="#" class="contact-btn bookrelease-btn">Send Message</a>
    <input type="submit" value="BRfile" class="contact-btn bookrelease-btn">
  </div>
</form>
&#13;
&#13;
&#13;

我寻找文件的PHP代码,但它的计算结果为false。

&#13;
&#13;
    if (array_key_exists($_POST['postBRfile'], $_FILES)) {
            // First handle the upload
            // Don't trust provided filename - same goes for MIME types
            // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
            $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES[$_POST['postBRfile']]['name']));
            if (move_uploaded_file($_FILES[$_POST['postBRfile']]['tmp_name'], $uploadfile)) {
                $mail->addAttachment($uploadfile, 'My uploaded file');
            }
 
    }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我不理解postBRfile

试试这个。

if (array_key_exists($_POST['BRfile'], $_FILES)) {
        // First handle the upload
        // Don't trust provided filename - same goes for MIME types
        // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
        $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES[$_POST['BRfile']]['name']));
        if (move_uploaded_file($_FILES[$_POST['BRfile']]['tmp_name'], $uploadfile)) {
            $mail->addAttachment($uploadfile, 'My uploaded file');
        }

}