I want to check if a directory contains a specific file(any type, image, pdf etc.) or not. If it contains the file, I want to provide a download link for this file, otherwise print "not exist"
. Unfortunately, my code is printing not exist
all the time even if the file exists in the directory. Here is my code:
<td> <?php
if (file_exists('plans/'.$RID)) {
echo"<a href='plans/$RID'>Plan</a>";
} else {
echo "not exists";
}
?> </td>
here is another code I also tried it but doesn't work:
<td> <?php
$plan= 'plans/'.$RID;
if (file_exists($plan)) {
echo"<a href='plans/$RID'>Plan</a>";
} else {
echo "not exists";
}
?> </td>
Provide an absolute path as parameter of your function :
If your script path is parent of plans directory, parameter could be
__DIR__ . '/plans'
for example.edit : To catch file with some extensions, you can create an array containing allowed extensions.