我正在尝试创建一个表单,该表单可以由带有附件的用户发送。表单工作正常,提交时发送电子邮件,但没有附加文件。
我的表格是:
<form method="post" class="flat-p-form p-form-flat-extra5color4" action="<?php the_permalink(); ?>" data-js-validate="true" data-js-highlight-state-msg="true" data-js-show-valid-msg="true">
<div class="form-group">
<label for="fotoattachment" class="p-label-required">Attachment <span style="color: red">(Attach Your Photos as A ZIP File.)</span></label>
<div class="input-group p-has-icon">
<input type="file" class="file form-control" id="fotoattachment" name="fotoattachment" required="required"/>
<span class="input-group-state">
<span class="p-position">
<span class="p-text">
<span class="p-required-text"><i class="fa fa-star"></i></span>
</span>
</span>
</span>
<span class="p-field-cb"></span>
<span class="input-group-icon"><i class="fa fa-paperclip"></i></span>
</div>
</div>
<button class="btn" type="submit" name="confirm"><i class="fa fa-share-square-o"></i> Submit</button>
</form>
我的PHP是:
if(isset($_POST[\'confirm\'])){
$fullname = $_POST[\'sudentname\'];
$email = $_POST[\'email\'];
$comment = $_POST[\'comment\'];
$batch = $_POST[\'batch\'];
$mailbody = \'Name :\'. $fullname . "\\r\\n".\'Email: \'.$email. "\\r\\n".\'Comment: \'.$comment. "\\r\\n".\'Batch: \'.$batch;
/* attachment */
move_uploaded_file($_FILES["fotoattachment"]["tmp_name"],WP_CONTENT_DIR .\'/uploads/\'.basename($_FILES[\'fotoattachment\'][\'name\']));
$attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["fotoattachment"]["name"]);
$to = \'[email protected]\';
$subject = \'Feedback from Website\';
$headers = \'From: \'.$fullname.\' <\'. $email. \'>\';
wp_mail( $to, $subject, $mailbody, $headers, $attachments );
}
我收到的是电子邮件,但不是附件。为什么会这样?
[UPDATE]
当我在提交表格后这样检查时:
foreach ($attachments as $key => $value) {
echo "$key = $value\\n";
}
输出是
Array