是否有人可以向我解释如何将上传的文件附加到使用wp\\U mail生成的电子邮件中?我已经建立了表单,但我可以在网上找到的所有问题都是指附加一个预先确定的文件,而不是用户上传的文件。
EDITI正在尝试使用wp\\u handle\\u upload:
if ( ! function_exists( \'wp_handle_upload\' ) ) require_once( ABSPATH . \'wp-admin/includes/file.php\' );
$uploadedfile = $_FILES[\'file\'];
$upload_overrides = array( \'test_form\' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
echo "File is valid, and was successfully uploaded.\\n";
var_dump( $movefile);
} else {
echo "Possible file upload attack!\\n";
}
。。。但我收到以下错误:“文件是空的。请上传更重要的内容…”我想这是因为我没有正确地传递附件变量。
“我的表单”字段如下所示:
<input type="file" name="uploaded_picture">
有人能指出我是如何把这两件东西绑在一起的吗?
最合适的回答,由SO网友:Kevin Nugent 整理而成
简而言之,我只是未能传入正确的变量:
if ( ! function_exists( \'wp_handle_upload\' ) ) {
require_once( ABSPATH . \'wp-admin/includes/file.php\' );
}
$uploadedfile = $_FILES[\'uploaded_file\'];
$upload_overrides = array( \'test_form\' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if( $movefile ) {
//echo "File is valid, and was successfully uploaded.\\n";
//var_dump( $movefile);
$attachments = $movefile[ \'file\' ];
wp_mail($to, $subject, strip_tags($message), $headers, $attachments);
} else {
echo "Possible file upload attack!\\n";
}
我的表单字段应为:
<input type="file" name="uploaded_file" accept="application/pdf">