Jump to content
php.lv forumi

no formas txt failaa


matx

Recommended Posts

kaads var paskaidrot kadelj man neizdodas ierakstiit neko txt failaa, daru sekojoshi: ir triis faili- index.php, apstradatajs.php, un dari.txt...

 

index.php saturs:

<form action="apstradatajs.php">
<input type="text" name="dati" style="width:200px; height:200px ">
<input type="submit" value="Saglabāt">
</form>

apstradatajs.php saturs:

<?php
$filename = 'dati.txt';
$somecontent = "$dati\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

  // In our example we're opening $filename in append mode.
  // The file pointer is at the bottom of the file hence 
  // that's where $somecontent will go when we fwrite() it.
  if (!$handle = fopen($filename, 'a')) {
        echo "Cannot open file ($filename)";
        exit;
  }

  // Write $somecontent to our opened file.
  if (fwrite($handle, $somecontent) === FALSE) {
      echo "Cannot write to file ($filename)";
      exit;
  }
  
  echo "Success, wrote ($somecontent) to file ($filename)";
  
  fclose($handle);

} else {
  echo "The file $filename is not writable";
}
?>

apstradatajs.php nokopeets no php.net maacoties par funkciju fwrite...

 

es veeletos lai ierakstot info index.php formaa vinja tiktu saglabaata txt failaa, php.net $somecontent = "$dati\n"; $dati vietaa bija raxtiits texts, un tad aizejot uz apstradatajs.php txt failaa tika ierakstiits tas texts, bet es gribeetu lai no formas tas textinjsh aizietu uz txt failu....

 

varbuut varat kko ieteikt?

 

paldies....

Link to comment
Share on other sites

Vai es pareizi saprotu, ka tajā dari.txt nekas neierakstās?

man škiet, ka problēma ir tajā, ka tu neesi pārliecinājies, vai register_globals ir on vai off...

īsāk sakot... pamēģini šo savu rindiņu:

$somecontent = "$dati\n";

aizvietot ar šo:

$somecontent = $_GET['dati'] . "\n";

Link to comment
Share on other sites

  • 2 weeks later...

nu tur jau taa lieta, ka es neiebraucu kur tas viss vareetu nestraadaat... un tur jau tikai 1 skripts ir... es domaaju ka vaina vareetu buut kkur sheit

 

global $gbfile;
     $tmp = trim($str);
     $fp=fopen($gbfile,'a+'); 
          flock($fp, LOCK_EX); 
               fwrite($fp, $tmp. "\n"); 
          flock($fp, LOCK_UN); 
     fclose($fp); 
}

 

meegjinaju uzlikt vienkaarshi 'a' , bet arii tas neliidzeeja...

domaaju maybe juus kko vareeetu ieteikt!

Link to comment
Share on other sites

ko iz echo, ja pārraksti šādi:

global $gbfile;
    $tmp = trim($str);
    echo($gbfile . '<br>');
    echo(''.(file_exists($gbfile)?'Fails atrasts<br>':'Fails nav atrasts<br>'));
    echo(''.(is_readable($gbfile)?'Failu var nolasīt<br>':'Failu nevar nolasīt<br>'));
    echo(''.(is_writable($gbfile)?'Failā var ierakstīt<br>':'Failā nevar ierakstīt<br>'));
    $fp=fopen($gbfile,'a+');
         flock($fp, LOCK_EX);
              fwrite($fp, $tmp. "\n");
         flock($fp, LOCK_UN);
    fclose($fp);
}

Link to comment
Share on other sites

lai no formas dabuutu ievadiitos datus ir jaalieto $_POST[] vai $_GET[], atkariiba no formas veida kas tev nav defineets pirmajaa piemeera apmeeram saadi

<form action="apstradatajs.php" method='post'>
<input type="text" name="dati">
<input type="submit" value="Saglabāt">
</form>

un peec tam dati ir savaacami ar

$somecontent = $_POST["dati"];

un nevajag sleegt ieksaa register_globals - palasi par security ieks php.net

Link to comment
Share on other sites

×
×
  • Create New...