【发布时间】:2019-08-23 02:05:48
【问题描述】:
我正在尝试使用 "extension X mime" 文件值通过 phpmailer 创建上传文件的交叉验证,系统正在处理我需要执行此操作的几乎所有文件,但特别是 .rtf 文件脚本不是工作。
扩展名消失了,如果文件是.rtf,脚本就无法得到这个。我正在使用这个脚本:https://stackoverflow.com/a/33349901/4623271 进行了一些修改。
代码中的下面是变量$ext,我可以在其中获取验证允许的任何文件的扩展名,.rtf 文件除外,当文件为.rtf 时,变量显然为空。
我尝试使用$ext = end(explode(".", $_FILES["uploadedFile"]["name"]));,但同样,.rtf 文件何时为空。
// mime verification
$finfo = new finfo(FILEINFO_MIME_TYPE);
if (false === $ext = array_search(
$finfo->file($_FILES['uploadedFile']['tmp_name']),
array(
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'rtf' => 'application/msword',
'odt' => 'application/vnd.oasis.opendocument.text',
'txt' => 'text/plain',
'pdf' => 'application/pdf',
),
true
)) {
$errorMsg .= "<br> Please, watch that the formats allowed are: \"doc\", \"docx\", \"rtf\", \"odt\", \"txt\", \"pdf\"' ";
}
感谢您花时间阅读本文。
【问题讨论】:
-
这是在 apache 上吗?你的 .htaccess 是什么样的?也可能是因为 php 无法解析 .rtf stackoverflow.com/questions/678192/…
-
感谢您的回答,我阅读了该页面,但我不想解析文件内容,我只想获取 .rtf 文件的扩展名并将其放入变量中它适用于其他文件类型。
-
这是在 apache 上吗?你有 .htaccess 文件吗?
-
不,这不是 Apache,它是 windows 服务器
-
Windows Server 是一个平台,不知道 PHP 是什么。您的意思是说您使用的是 MS 风格的 Web 服务器 IIS?