![](/img/trans.png)
[英]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.