Jump to content
php.lv forumi

PHP : Edit TXT File !


FT3

Recommended Posts

form.php

<form action="index.php?action=form" method="post">
ID:<input type="text" name="id" />
<input type="submit" />
</form>

<form action="index.php?action=processscript" method="post">

<input type="text" name="content" value="
<?
$id = $_POST['id'];
$fn = "inc/data/io_$id.dat";
print htmlspecialchars(implode("",file($fn)));
?> 
" />
<br>
<input type="submit" value="Change!"> 
</form>

 

processscript.php

<?
$fn = "inc/data/io_2.dat";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php?action=form\" />\n";
?>

 

 

Ka lai uzstaisit lai processscript.php scripta , taja 2 vieta ielikt $id no form.php

Edited by FT3
Link to comment
Share on other sites

Mans domāt, ka varētu tikt galā ar

<? include 'form.php' ?>

un tad to $id paņemt no form.php

 

Otrs variants, ko pats izmantoju ikdienā, bez nekādiem liekiem failiem utt, ir šāds:


<? if($_POST['input_submit']){
   echo $_POST['input_text'];
};?>

<form method="post" action="">
   <input type="text" name="input_text" />
   <input type="button" name="input_submit" value="OK" />
</form>

 

Works like a charm :)

 

Tikai aptaisi, ko Tev tur tieši vajag, un visam ir jāstrādā.

Link to comment
Share on other sites

kautka ta ..

 

<form action="index.php?action=form" method="post">
ID:<input type="text" name="id" />
<input type="submit" />
</form>

<?
if($_POST['gogo'])
{

$id = $_POST['id'];
$fn = "inc/data/io_$id.dat";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php?action=form\" />\n";

}
;?>


<form method="post" action="">

<input type="text" name="content" value="
<?
$id = $_POST['id'];
$fn = "inc/data/io_$id.dat";
print htmlspecialchars(implode("",file($fn)));
?> 
" />
<br>
<input type="submit" value="Change!" name ="gogo" > 
</form>

 

problema ir tada , viņš ataisa , failu pec id pieprasijuma , bet saglabo to ar nosaukumu io_.dat

kas man nepareizi ?

Edited by FT3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...