簡體   English   中英

使用php從名稱“ sample”開始檢查文件是否存在

[英]checking existence of file start from name “sample” using php

有人可以幫助我如何使用PHP檢查特定文件夾中以sample1.pdfsample12.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.

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