我正在寻找一个列出/描述基于上传的文件
我有以下脚本。它接受上传的文件和文件类型。将其与数组进行比较以检查是否允许该类型,然后继续执行脚本。
php
分配的文件类型的清单。我有以下脚本。它接受上传的文件和文件类型。将其与数组进行比较以检查是否允许该类型,然后继续执行脚本。
$file = $_FILES['attachment']['tmp_name'];
//check file is correct type
$fileType = $_FILES['attachment']['type'];
// array of allowed file extensions
$fileTypeArray = ["application/pdf", "application/doc", "application/docx", "application/rtf", "application/txt", "application/odf", "application/msword"];
// now check that the file type matches that of the array.
if (!in_array($fileType, $fileTypeArray)){
我想允许上传任何doc
, pdf
, txt
等格式的文件。这个功能旨在处理上传的简历。如果您有更好的解决方案,请告诉我。谢谢!
$fileTypeArray
,除非你想允许所有现有类型? - Félix Adriyel Gagnon-Grenier