[英]Get file names from 1 to 5
標題不太清晰,但問題容器更清晰。
我有以下代碼:
if (!file_exists(**I_WANT_HELP_ON_THIS**)) {
header("Location: error.php");
}
我想檢查以下文件(file1.txt-file2.txt-file3.txt-file4.txt-file5.txt)是否存在(但使用簡單的代碼)..那么I_WANT_HELP_ON_THIS應該是什么 ?
我不想使用:
if (!file_exists('file1.txt')) {
header("Location: error.php");
}
if (!file_exists('file2.txt')) {
header("Location: error.php");
}
etc...
謝謝!
使用邏輯或||
運算符獲得一個條件:
if (!file_exists('file1.txt') || !file_exists('file2.txt')
|| !file_exists('file3.txt') || !file_exists('file4.txt') || !file_exists('file5.txt')) {
header("Location: error.php");
}
您可以通過使用數組來解決此問題,在數組中定義要檢查的所有文件(文件名),然后像這樣遍歷該數組
$files = array("file1.txt", "file2.txt",...);
foreach($files as $file) {
if(!file_exists($file) {
header("Location: error.php");
exit(); //or just break; if you still need to do something else
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.