簡體   English   中英

如何通過php函數獲取特定目錄路徑中的文件信息,例如文件mime類型和文件名?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM