[PHP] Opätovný zápis do súbora

Programovacie jazyky, rady, poradňa...
Majo053
Medium Expert
Medium Expert
Používateľov profilový obrázok
Príspevky: 126
Registrovaný: 14 aug 2006, 13:39
Bydlisko: Somewhere

[PHP] Opätovný zápis do súbora

Príspevok od používateľa Majo053 »

Ahoj preco mi nejde zapisovat do subora test.txt ? Chcem aby bola v subore hodnota 000001 a pri vykonani kodu aby sa zvysila na 000002 atd....

Kód: Vybrať všetko

<?php

$incrementcontents = "1";
$incrementfile = "./test.txt";
$handle = fopen($incrementfile, 'w')or die("subor nejde otvorit");	
$incrementcontents = file_get_contents($incrementfile);
$incrementcontents = $incrementcontents++;
fwrite($handle,$incrementcontents);
fclose($handle);
$file = file_get_contents($incrementfile);
echo $file;

?>
audiotrack
VIP
VIP
Používateľov profilový obrázok
Príspevky: 25958
Registrovaný: 09 sep 2005, 18:39
Kontaktovať používateľa:

Príspevok od používateľa audiotrack »

Kód: Vybrať všetko

$handle = fopen($incrementfile, 'w')or die("subor nejde otvorit");   
zmeň na

Kód: Vybrať všetko

$handle = fopen($incrementfile, 'w+')or die("subor nejde otvorit");   
Majo053
Medium Expert
Medium Expert
Používateľov profilový obrázok
Príspevky: 126
Registrovaný: 14 aug 2006, 13:39
Bydlisko: Somewhere

Príspevok od používateľa Majo053 »

dakujem ale to som skusal a nejde mi to stale. Subor mam prazdny!

Potreboval by som aby sa mi to stala zvysovalo.
ST1GD3R
Light Star
Light Star
Používateľov profilový obrázok
Príspevky: 250
Registrovaný: 20 apr 2009, 11:32
Bydlisko: Doma

Príspevok od používateľa ST1GD3R »

Toto

Kód: Vybrať všetko

$handle = fopen($incrementfile, 'w')or die("subor nejde otvorit");  
Na toto

Kód: Vybrať všetko

$handle = fopen($incrementfile, 'a')or die("subor nejde otvorit");  
chrono
VIP
VIP
Používateľov profilový obrázok
Príspevky: 7127
Registrovaný: 25 dec 2006, 15:17

Príspevok od používateľa chrono »

Kód: Vybrať všetko

<?php 
 $incrementcontents = "1"; 
 $incrementfile = "./test.txt"; 

 $incrementcontents = file_get_contents($incrementfile); 
 $incrementcontents++; 

 $handle = fopen($incrementfile, 'w') or die("subor nejde otvorit");
 fwrite($handle, $incrementcontents); 
 fclose($handle); 

 $file = file_get_contents($incrementfile);

 echo $file;
?>
Majo053
Medium Expert
Medium Expert
Používateľov profilový obrázok
Príspevky: 126
Registrovaný: 14 aug 2006, 13:39
Bydlisko: Somewhere

Príspevok od používateľa Majo053 »

chrono napísal:

Kód: Vybrať všetko

<?php 
 $incrementcontents = "1"; 
 $incrementfile = "./test.txt"; 

 $incrementcontents = file_get_contents($incrementfile); 
 $incrementcontents++; 

 $handle = fopen($incrementfile, 'w') or die("subor nejde otvorit");
 fwrite($handle, $incrementcontents); 
 fclose($handle); 

 $file = file_get_contents($incrementfile);

 echo $file;
?>
chrono dakujem pekne takto som to chcel! Chyba bola v jednom riadku... :oops:
Napísať odpoveď