stencilz Posted March 7, 2007 Report Share Posted March 7, 2007 $file = "max.txt"; $open = fopen($file, "r+"); $max = fread($open, filesize($file)); if($count > $max) { fwrite($open, $count); } fclose($open); gribu ierakstīt maksimālo lietotāju skaitu, bet kā lai nodzēš iepriekšējo skaitu? man saglabā tā 0123... Link to comment Share on other sites More sharing options...
andrisp Posted March 7, 2007 Report Share Posted March 7, 2007 Nu tā viņš dara. Atver divas reizes to failu. Vispirms ar "r" un tad ar "w". Link to comment Share on other sites More sharing options...
Val Posted March 7, 2007 Report Share Posted March 7, 2007 skaties fopen otro parametru manuālī. Link to comment Share on other sites More sharing options...
stencilz Posted March 7, 2007 Author Report Share Posted March 7, 2007 (edited) $file = "max.txt"; $open = fopen($file, "r+"); $max = fread($open, filesize($file)); if($count > $max) { $open_2 = fopen($file, "w"); fwrite($open_2, $count); } fclose($open); izdarīju šādi :) Edited March 7, 2007 by stencilz Link to comment Share on other sites More sharing options...
andrisp Posted March 7, 2007 Report Share Posted March 7, 2007 Val, es arī skatījos, bet īsti nemācēju atrast īsto flagu ar kuru, var nolasīt un uzrakstīt pa virsu. Link to comment Share on other sites More sharing options...
Val Posted March 7, 2007 Report Share Posted March 7, 2007 (edited) 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. ja nevajag lasīt, tad tikai 'w' Edited March 7, 2007 by Val Link to comment Share on other sites More sharing options...
andrisp Posted March 7, 2007 Report Share Posted March 7, 2007 (edited) Val, pamēģini pats: $file = "bla.txt"; $open = fopen($file, "w+"); $content = fread($open, filesize($file)); echo $content; w+ iztukšo failu pie atvēršanas. Tākā nolasīt neko nevar (pēc tam, protams, varam nolasīt, bet mums jau vajag tieši oriģinālos datus nolasīt). Edited March 7, 2007 by andrisp Link to comment Share on other sites More sharing options...
Val Posted March 7, 2007 Report Share Posted March 7, 2007 Viņam jau nav svarīgs saturs, kas tur ir tagad. Pointeris uz faila sākumu un iepriekšējo nodzēšam un rakstam savu iekšā. p.s. Iespējams, ka vēl neesmu pamodies... Link to comment Share on other sites More sharing options...
andrisp Posted March 7, 2007 Report Share Posted March 7, 2007 Pievērs uzmanību šim: if($count > $max) { Link to comment Share on other sites More sharing options...
Val Posted March 7, 2007 Report Share Posted March 7, 2007 Beidzot izpratu, ko stencilz grib panākt. Link to comment Share on other sites More sharing options...
john.brown Posted March 7, 2007 Report Share Posted March 7, 2007 Un naf viņu divreiz vērt vaļā? $open = fopen($file, "r+"); $max = fread($open, filesize($file)); if($count > $max) { fseek($open,0); ftruncate($open,0); fwrite($open, $count); } fclose($open); Link to comment Share on other sites More sharing options...
Recommended Posts