如何通过ID调用文件是否存在



我有一个文件在/pdf/0001_test.pdf
0001为"id", test.pdf"是一个文件。如何调用"id"?基于这个"if file exists"&;代码

<?php
$filename = "pdf/0001_test.pdf";
if (file_exists($filename)) {
echo "File exist.";
} else {
echo "File does not exist.";
}
?>
<?php
$file = "test.pdf";
$filename = "pdf/".$d['id']."_".$file;
if (file_exists($filename)) {
echo "<p>".$fileName." exists.</p>";
} else {
echo "<p>".$fileName." not exists.</p>";
}
?>

这是我的完整代码,先生

<table border="1">
<tr>
<th>NO</th>
<th>Nama</th>
<th>NIM</th>
<th>PDF FILE</th>
<th>OPSI</th>
</tr>
<?php 
include 'koneksi.php';
$no = 1;
$data = mysqli_query($koneksi,"select * from file");
while($d = mysqli_fetch_array($data)){
?>
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $d['nama']; ?></td>
<td><a href="pdf/<?php echo $d['pdf']; ?>" target="_blank">
<b>
<?php
$filename = "pdf/0001_test.pdf";
if (file_exists($filename)) {
echo "File exist.";
} else {
echo "File does not exist.";
}
?>
</b>
</td>
<td><?php echo $d['alamat']; ?></td>
<td>
<a href="edit.php?id=<?php echo $d['id']; ?>">EDIT</a>
<a href="hapus.php?id=<?php echo $d['id']; ?>">HAPUS</a>
</td>
</tr>
<?php 
}
?>
</table>

最新更新