简体   繁体   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目录以获取此文件夹内未知文件的名称和类型。

You could make use of finfo_file() in PHP. 您可以在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

Try this it'll get the file name and extensions 试试这个,它将获得文件名和扩展名

$files=glob("files/*");    // files is directory name and * mean all types of files    
foreach ($files as $file) {
    echo $file."<br />";
}

It'll return file name and format!!! 它会返回文件名和格式!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM