file_get_contents ile direkt okuma yapılabilir.
Dizin olaylarını kontrol etmeyi unutmayın.
<form method="post">
<label for="kategori">Kategori Seçin:</label>
<select name="kategori" id="kategori">
<option value="Adana">Adana</option>
<option value="Mersin">Mersin</option>
<option value="Diyarbakır">Diyarbakır</option>
</select>
<input type="submit" name="submit" value="Göster">
</form>
<?php
if (isset($_POST['submit'])) {
$secilenKategori = $_POST['kategori'];
$dosyaAdi = $secilenKategori . '.txt'; // Seçilen kategoriye uygun dosya adını oluşturun
if (file_exists($dosyaAdi)) {
$dosyaIcerik = file_get_contents($dosyaAdi);
echo "<h1>$secilenKategori</h1>";
echo "<pre>$dosyaIcerik</pre>";
} else {
echo "<p>$secilenKategori kategorisine ait dosya bulunamadı.</p>";
}
}
?>
aşağıda kategoriyi isimlerini listeleyen kod var bana ilk verdiğim kodlar üzerinde nasıl yapacağımı göstere bilirmisin
<?php
if($ililcesorulmusmu != 1){
?>
<li class="product-widget-dropitem ">
<button type="button" class="product-widget-link active"><i class="fa fa-map-marker"></i><a href="firma/<?= $tumunuGorUrl ?>" class="text-secondary"><?= $searchCompanyFetchIl ?></a></button>
<ul class="product-widget-dropdown" style="display: block;">
<?php
$theCompanyCategoryQry= $db->query("SELECT * FROM ililce where ilce is not null and il ='$searchCompanyFetchIl'");
$theCompanyCategoryFetch = $theCompanyCategoryQry->fetchAll(PDO::FETCH_ASSOC);
$allIlceId = "";
foreach($theCompanyCategoryFetch as $theCC){
$allIlceId .= $theCC['id'] . ",";
?>
<li><a href="firma/<?= $theCC['url'] ?>"><?= $theCC['ilce'] ?></a></li>
<?php
}
?>
</ul>
</li>
<?php } ?>
<?php
foreach($allCompanyCategoryFetch as $allCC){
$allCCIl=$allCC['il'];
?>
<li class="product-widget-dropitem">
<button type="button" class="product-widget-link"><i class="fa fa-map-marker"></i><a href="firma/<?= $allCC['url'] ?>" class="text-secondary"><?= $allCCIl ?> </a></button>
<ul class="product-widget-dropdown">
<?php
$theCompanyCategoryQry= $db->query("SELECT * FROM ililce where ilce is not null and il ='$allCCIl'");
$theCompanyCategoryFetch = $theCompanyCategoryQry->fetchAll(PDO::FETCH_ASSOC);
foreach($theCompanyCategoryFetch as $theCC){
?>
<li><a href="firma/<?= $theCC['url'] ?>"><?= $theCC['ilce'] ?></a></li>
<?php
}
?>
</ul>
</li>
<?php
}
?>