Jump to content
php.lv forumi

Kļūda izmantojot fopen (php $_GET)


-=HELLBENDER=-

Recommended Posts

Sveiki.

 

Cenšos izveidot adminpanelim lapu, kur varētu rediģēt citas lapas..

 

Apmēram šāds izskatās skripts (nav garš, tapēc rakstīšu te pat);

<form action="edit.php" method="get">
Name: <input type="text" name="fname" />
<input type="submit" />
</form> 

 

<?php
$fn = $_GET["fname"];

if (isset($_POST['content']))
{
   $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!");
}
?>
<p>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
   <textarea rows="30" cols="80" name="content"><?php readfile($fn); ?></textarea>
   <input type="submit" value="Edit"> 
</form>

 

 

kad ievadu faila nosaukumu, nākamajā lapā atver veiksmīgi un parāda faila saturu, bet kad rediģēju un uzspiežu edit, izmet "Error opening file in write mode!". Mēģināju arī $_POST. Kur varētu būt vaina? :?

 

 

ps. Starp citu, topic preview režīmā nestrādā HTML un PHP tagi kā vajag (neiekrāsojas).

Edited by -=HELLBENDER=-
Link to comment
Share on other sites

  • Replies 44
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Paldies, bet kļūda nemainīga..

 

<?php
$fn = $_GET["fname"];

if (isset($_POST['content']))
{
   $fp = file_get_contents($fn, true) or die ("Error opening file in write mode!");
   file_put_contents($fp,$content);
}
?>

Edited by -=HELLBENDER=-
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...