[英]checking existence of file start from name “sample” using php
有人可以帮助我如何使用PHP检查特定文件夹中以sample1.pdf
, sample12.pdf
类的任何名称开头的文件的存在吗? 下面是我检查单个文件的代码。
<html>
<?php
if(file_exists("properties/".$owner."/".$property."/sample1.pdf") )
?>
</html>
PHP函数glob( 在此处 )将为您提供匹配的文件数组。 因此,您可以执行以下操作:
$files = glob("properties/{$owner}/{$property}/sample*.pdf");
然后,这将返回“ properties / {$ owner} / {$ property} /”目录中以“ sample”开头且扩展名为.pdf的文件数组。
然后,您可以遍历文件并执行所需的操作
//Check if there are any files and there were not any FATAL errors
if (count($files) > 0 && $files !== FALSE) {
foreach ($files as $file) {
//Do something here
}
} else {
//There were no matching files
}
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.