2016-04-02 17 views
0
İşte

benim kodudur: kullanıcı yeni bir sayfa bir oturum 1 her eklenmesi yoluyla oluşturulan bir düğme tıklama yapmasıPHP dosyası içerir - işlevleriyle kendiliğinden geçersiz kılma

<?php 
 

 

 
    if(isset($_POST['load_more'])){ 
 
\t 
 
     \t $variable = $_SESSION['variable']++; 
 
     \t generateNewPage($detail_locator, $variable); 
 
     \t 
 
    } 
 
    
 
    function generateNewPage($detail_locator, $variable){ 
 
    
 

 
    \t   $relative_path = "load_more/newfile $variable .php"; 
 
\t \t $myfile = fopen($relative_path, "a") or die("Unable to open file!"); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 

 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 

 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t fclose($myfile); 
 
\t \t 
 
\t \t include "load_more/newfile $variable .php"; 
 
\t \t 
 
    
 
    } 
 
    
 

 
?> 
 
<div id="reload_section"> 
 
</ul> 
 
<center><br /> 
 
\t <form method="post"> 
 
\t \t <input type="submit" value="Load More" name="load_more" class="load_more_content" /> 
 
\t </form> 
 
</center> 
 
</div>

Temelde, her zaman Fopen'e zaman.

Kullanıcı bu düğmeyi tıkladığında, bir sayfa oluşturulur, sonra bu sayfa eklenir.

Ancak, işlev her çalıştırıldığında, içerme ifadesi kendisini geçersiz kılar ve yalnızca yeni oluşturulan sayfaların en yenisi eklenir.

Kullanıcı tarafından düğmeyi tıklattıkça, oluşturulan her sayfanın aşamalı olarak eklenmesini istiyorum.

Bu mümkün mü? Ve eğer öyleyse nasıl?

Güncellemeler @ David Jones: Dosya yolları takip etmek için bir dizi sahip olmalı ve fonksiyon için dosya yolunu eklemek gerekir

<?php 
 

 
\t if (!isset($_SESSION['files'])) { 
 
    \t $_SESSION['files'] = []; // or array() if your PHP version is < 5.4 
 
\t } 
 

 
\t if(isset($_POST['load_more'])){ 
 
\t 
 
     \t \t $variable = $_SESSION['variable']++; 
 
     \t \t generateNewPage($detail_locator, $variable); 
 
     \t 
 
    } 
 
    
 
    function generateNewPage($detail_locator, $variable){ 
 
    
 

 
    \t $relative_path = "load_more/newfile $variable .php"; 
 
\t \t $myfile = fopen($relative_path, "a") or die("Unable to open file!"); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 

 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 

 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t $new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>"; 
 
\t \t $txt = $new_code; 
 
\t \t fwrite($myfile, $txt); 
 
\t \t 
 
\t \t fclose($myfile); 
 
\t \t 
 
\t \t $SESSION['files'][] = "load_more/newfile $variable .php"; 
 
\t \t 
 
\t \t foreach ($_SESSION['files'] as $file) { 
 
    \t \t include $file; 
 
\t \t } 
 
\t \t 
 
    
 
    } 
 
    
 

 
?> 
 
<div id="reload_section"> 
 
</ul> 
 
<center><br /> 
 
\t <form method="post"> 
 
\t \t <input type="submit" value="Load More" name="load_more" class="load_more_content" /> 
 
\t </form> 
 
</center> 
 
</div>

cevap

0

dizi. Daha sonra aynı işlevde veya tercihen ayrı bir işlevde dizinin içinden geçerek her dosyayı dahil edersiniz.

Fonksiyonunuzun dışında yeni bir dizi tanımlayacaksınız, burada oturumda bunu yapıyorum, böylece kolayca erişilebilir. Fonksiyonun değişimde Şimdi

if (!isset($_SESSION['files'])) { 
    $_SESSION['files'] = []; // or array() if your PHP version is < 5.4 
} 

bu satırı: Buna

include "load_more/newfile $variable .php"; 

:

$_SESSION['files'][] = "load_more/newfile $variable .php"; 

Şimdi dosyalar dizisinde ilerleyebilir ve her birini kapsar. Bu, generateNewPage işlevinde veya ayrı bir işlevde yapılabilir, ancak generateNewPage işlevinden çağrılabilir.

foreach ($_SESSION['files'] as $file) { 
    include $file; 
} 

Umarım bu açıktır. Herhangi bir sorununuz olursa lütfen bize bildirin.

+0

Teşekkür ederim @David Jones, küçük bir sorunum var. Önerilen kodunuzu koydum sırayla düzgün çalışmıyor gibi görünmüyor (düzenlemelerde yukarıda görüldüğü gibi). Baska öneri? –

+0

Kodun sırasını yanlış yazdım (düzenlemelerin üzerinde) –

+0

Kodumda bir yazım hatası vardı. Düzenlemelerimi kontrol et. Ayrıca kod test edilmedi ve çözümümüzü gösteren bir rehber. Sizin için işe yarayıp başlamadığına ve eğer orijinal kodunuzun neden beklentilerinizi karşılamadığının farkına varmaya çalışın. Daha fazla açıklamaya ihtiyacınız varsa bana bildirin. –