Jump to content
php.lv forumi

Kas šeit nepareizs


KarlisBa

Recommended Posts

Šajā formā tiek ielādēta informācija:

 

<form action="apstiprinat.php" method="post">
<textarea rows="20" cols="50" name="content">
<?
$fn = "/edit/test.txt";
print htmlspecialchars(implode("",file($fn)));
?> 
</textarea><br>
<input type="submit" value="Mainīt"> 
</form>

 

Pēc apstiprināšanas nonāk uz failu apstiprinat.php, bet izmet šādu erroru

 

Warning: fopen(/edit/test.txt) [function.fopen]: failed to open stream: No such file or directory in C:\AppServ\www\edit\apstiprinat.php on line 4
Nevar pārrakstīt!

 

Šim skriptam:

 

<?
$fn = "/edit/test.txt";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Nevar pārrakstīt!");
fputs($fp,$content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1257\" />\n";
?>

 

Kas par gļuku uz 4. rindas?

Edited by shalonik
Link to comment
Share on other sites

Warning: fopen(/edit/test.txt) [function.fopen]: failed to open stream: No such file or directory in C:\AppServ\www\edit\apstiprinat.php on line 4
Nevar pārrakstīt!

tas jau visu izsaka.. /edit/test.txt tāds fails neeksistē

 

pamēģini edit/test.txt bez sleša pirms edit!

Edited by Pentiums
Link to comment
Share on other sites

<form action="apstiprinat.php" method="post">

<textarea rows="20" cols="50" name="content">

<?

$fn = "/edit/test.txt";

print htmlspecialchars(implode("",file($fn))); // Ja vel nepamaniji tad rekur <-----

?>

</textarea><br>

<input type="submit" value="Mainīt">

</form>

Edited by Mikijs
Link to comment
Share on other sites

Rakstit failaa

<?php

$vards = "vards";

$meils = "meils";

$fp = fopen("test.txt","a");

$fp = fopen("test.txt","a");

if(!$fp) {

print "failu nevar atvert";

exit;

}

$stringtowrite=$vards."|".$meils;

fwrite($fp, $stringtowrite);

fclose($fp);

?>

 

Lasīt no faila

ātrākais un vieglākais variants ir

<?php

readfile("test.txt");

?>

 

nu bet =]

<?php

$array = file("test.txt");

foreach($array as $row) {

$line = explode($row, "|");

print "Vards: $line[0], Meils: $line[1]<br>";

}

print count($array);

if (in_array("Arturs ",$array)) {

print "Vards arturs nav saja faila<br>";

}

srand ((float) microtime() * 10000000);

$random_key=array_rand($array);

$line = explode($array[$random_key], "|");

 

print "Luk tev randoms vards un meils: $line[0] : $line[1]<br>";

?>

Link to comment
Share on other sites

×
×
  • Create New...