首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >fileinfo不限制pdf

fileinfo不限制pdf
EN

Stack Overflow用户
提问于 2013-03-28 16:15:02
回答 1查看 473关注 0票数 0

我正在使用下面的脚本来验证上传的文件是否为pdf,以及是否与phpmailer一起发送。它发送电子邮件,但没有附件。此外,它还允许我附加非pdf文件。请帮帮忙。

代码语言:javascript
复制
ob_start();
require("class.phpmailer.php");

if(isset($_FILES['upload']['tmp_name'])){
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime=finfo_file($finfo, $_FILES['upload']['tmp_name']);
if($mime=='application/pdf'){

$message = "some message";
$mail = new PHPMailer();
$mail->From     = ('sample@youdomain.net');
$mail->AddAddress=('sample@youdomain.net');
$mail->Subject  = "Submitted files";
$mail->Body     = $message;
$mail->WordWrap = 50;

foreach($_FILES['upload']['tmp_name'] as $upload) 
if(!empty($upload)) {
$mail->AddAttachment($upload);
}
$mail->Send();

header("Location: thankyou.php");
exit();     
}}
EN

回答 1

Stack Overflow用户

发布于 2013-03-28 16:21:55

目前,您拥有:

代码语言:javascript
复制
if( ... ) { 
    ...
    if($mime=='application/pdf') {
    }
}
// some code you want to be executed
// only if the mime type is application/pdf

但是你想要:

代码语言:javascript
复制
if (...) {
  ..
  if ($mime=='application/pdf') {
        // place the code you want to be executed
        // only if the mime type is application/pdf
        // here - before the closing }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15676971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档