[英]How can I get the file type and file name of a unknown file from a specific folder by PHP?
[英]How can I get the information of the file in a specific directory path such as file mime type and file name by php function?
例如,使用php掃描/ favor目錄以獲取此文件夾內未知文件的名稱和類型。
您可以在PHP中使用finfo_file()
。
<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
foreach (glob("*") as $filename) {
echo finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);
?>
OUTPUT:
text/html
image/gif
application/vnd.ms-excel
試試這個,它將獲得文件名和擴展名
$files=glob("files/*"); // files is directory name and * mean all types of files
foreach ($files as $file) {
echo $file."<br />";
}
它會返回文件名和格式!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.