[英]PHP check if file exists and not directory
我讀過file_exists()
如果指向一個目錄,也可以返回turn。 檢查是否只退出文件的最快方法是什么?
目前我有:
/**
* Check if the file exists.
*
* @return bool
*/
public function exists() {
if(is_null($this->_file)) return false;
return (!is_dir($this->_file) && file_exists($this->_file)) ? true : false;
}
我發現很多帖子都與檢查文件是否以PHP格式退出有關,但沒有任何內容涉及該目錄以及如何最好地檢查這個。
這種方法可以調用1000次,所以我可以盡可能快地完成它。
您正在尋找is_file
函數:
public function exists() {
return $this->_file !== null && is_file($this->_file);
}
public function exists() {
return !is_dir($this->_file) && file_exists($this->_file);
}
您可以嘗試僅用於文件 。 它是一個自定義函數,你將調用而不是file_exists
函數
function custom_file_exists($filePath)
{
if((is_file($filePath))&&(file_exists($filePath))){
return true;
}
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.