亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果在聯系表格 7 中上傳的文件是二進制文件,則阻止

如果在聯系表格 7 中上傳的文件是二進制文件,則阻止

PHP
Helenr 2022-10-14 14:36:37
有人可以幫助阻止聯系表格7中的二進制文件,即如果game.exe重命名為game.docx并上傳,那么它必須被阻止到目前為止,我已經嘗試在 wp-includes/functions.php 中添加以下代碼add_filter('wpcf7_validate_file*', 'cf7_custom_file_validation', 10, 2);add_filter('wpcf7_validate_file', 'cf7_custom_file_validation', 10, 2);function cf7_custom_file_validation ($result, $tag) {    if ($tag->name === 'your-file') {        $contentType = mime_content_type($_FILES[$tag->name]['tmp_name']);        if ($contentType !== 'application/docx' && $contentType !== 'application/pdf' && $contentType !== 'application/doc'&& $contentType !== 'application/rtf') {            $result->invalidate($tag, 'This file type is not supported');        }    }    return $result;}這允許我上傳 pdf 文件并檢查 pdf 是否為二進制和塊。但在 rtf、doc 和 docx 中它不起作用
查看完整描述

1 回答

?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

這是因為您正在檢查錯誤的 mime 類型。

.doc: application/msword
.docx: application/vnd.openxmlformats-officedocument.wordprocessingml.document


查看完整回答
反對 回復 2022-10-14
  • 1 回答
  • 0 關注
  • 123 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號