[英]How to check whether a file exists or not without knowing its directory in PHP?
[英]How to check whether a file is exists in any one of the folders of the root directory
我有一個根目錄(probeta)。在那兒,我又有3個子文件夾,如hr,admin,super
。 如何檢查這3個文件夾中是否存在文件?
我嘗試了這段代碼..但它總是轉到`super / notifications / filename..``
<?php
$dir="../super/notifications/";
$dir1="../admin/notifications/";
if(file_exists($dir. $row['file']))
{
?>
<a href='../super/notifications/<?php echo $row['file']; ?>' target='_blank' >View Details</a>
<?php
}
else if(file_exists($dir1. $row['file']))
{
?>
<a href='../admin/notifications/<?php echo $row['file']; ?>' target='_blank' >View Details</a>
<?php
}
else
{
?>
<a href='../hr/notifications/<?php echo $row['file']; ?>' target='_blank' >View Details</a>
<?php
}
?>
//請幫幫我...在將文件上傳到數據庫時,有沒有辦法將文件存儲到3個文件夾中?
在if語句中檢查所有條件
<?php
$dir="../super/notifications/";
$dir1="../admin/notifications/";
$dir2="../hr/notifications/";
if(file_exists($dir. $row['file'])|| file_exists($dir2. $row['file']) || file_exists($dir2. $row['file']))
{ ?>
<a href='<?php if(file_exists($dir. $row['file'])) echo $dir;else if(file_exists($dir1. $row['file'])) echo $dir1;else if(file_exists($dir2. $row['file'])) echo $dir2;?>/<?php $row['file']; ?>' target='_blank' >View Details</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.