Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Closed TopicStart new topic
> [PHP] Praca z plikiem
nortalf
post 1.09.2008, 12:36:03
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.09.2008

Ostrzeżenie: (0%)
-----


Witam Forumowiczów. Mam pytanie co jest nie tak z tym skryptem, ponieważ nie spełnia się warunek zapisu do pliku.

<?PHP
$plik = "save.txt";
$uchwyt = @fopen ($plik, "r");
if ($uchwyt) {
while (!feof($uchwyt))
{
$buffer = fgets($uchwyt, 4096);
$txt=$txt.$buffer;
}
fclose ($uchwyt);
}

$imieinazwisko=$_POST["imieinazwisko"];
$mail=$_POST["mail"];
$tresc=$_POST["tresc"];
$nowedane="Imie i nazwisko: $imieinazwisko; e-mail: $mail; tresc: $tresc";
$data=date("d-m-y");
$dane=$txt."\n___dodano: $data:\n".$nowedane;
$fp = fopen($plik, 'r+');
fseek($fp, 0);
$testzapisu=fwrite($fp, $dane);
fclose($fp);

if ($testzapisu) {
echo'<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Content-Language" content="pl">
<title>Pytanie</title>
</head>
<body>
<div align="center">
Twoje dane: ImiÍ i nazwisko'.$imieinazwisko.'<br>
e-mail: '.$mail.'<br>
Tresc: '.$tresc.'<br>
<b>zostały zapisane!</b><br><br>
</div>
</body>
</html>';
}
else
{
echo'<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Content-Language" content="pl">
<title>Error</title>
</head>
<body>
<div align="center">Wystapil blad zapisu!<br><br>
</div>
</body>
</html>';
}
?>


Dzięki za pomoc. Pozdrawiam

Poniżej ciałko html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Content-Language" content="pl">
<title>Pytanie</title>
</head>
<body>
<div align="center">
<form action="save.php" method="post">
<table border="0" colspan="2">
<tr>
<td style="font-family: verdana; font-size: 12px; color: #1c1e6c;">Imie i nazwisko: </td>
<td><input type="text" name="imieinazwisko"></td>
</tr>
<tr>
<td style="font-family: verdana; font-size: 12px; color: #1c1e6c;">adres e-mail</td>
<td><input type="text" name="mail"></td>
</tr>
<tr>
<td style="font-family: verdana; font-size: 12px; color: #1c1e6c;">Treść</td>
<td><textarea name="tresc" rows="10" cols="50" ></textarea></td>
</tr>
<tr>
<td style="font-family: verdana; font-size: 12px; color: #1c1e6c;"></td>
<td><INPUT TYPE="submit" VALUE="Zapisz"></td>
</tr>
</table>
</form>
</div>
</body>
</html>

Ten post edytował nortalf 1.09.2008, 12:40:23
Go to the top of the page
+Quote Post
Piniek
post 1.09.2008, 12:37:47
Post #2





Grupa: Przyjaciele php.pl
Postów: 463
Pomógł: 49
Dołączył: 27.12.2007
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Proszę dodać odpowiedni bbcode.


--------------------
Go to the top of the page
+Quote Post
JoShiMa
post 1.09.2008, 12:41:24
Post #3





Grupa: Zarejestrowani
Postów: 1 374
Pomógł: 149
Dołączył: 1.03.2006

Ostrzeżenie: (0%)
-----


Może zapisał zero bajtów. Spróbuj
  1. <?php
  2. if ($testzapisu !== FALSE) {
  3. ?>


I upewnij się, że ten plik się w ogóle otwiera i czy masz prawa do zapisu w nim.


--------------------
Go to the top of the page
+Quote Post
nortalf
post 1.09.2008, 12:48:59
Post #4





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.09.2008

Ostrzeżenie: (0%)
-----


Niestety ten sam efekt :/ nawet jak zamienie r+ na w+

$fp = fopen($plik, 'w+');

dupa blada
Go to the top of the page
+Quote Post
JoShiMa
post 1.09.2008, 12:55:05
Post #5





Grupa: Zarejestrowani
Postów: 1 374
Pomógł: 149
Dołączył: 1.03.2006

Ostrzeżenie: (0%)
-----


Jednym słowem nie ma takiego pliku tak?

1. Sprawdź, czy jest taki plik tam gdzie się go spodziewasz.
2. W fopen daj pełną ścieżkę dostępu do pliku.
3. Upewnij się, że masz prawa dostępu do pliku i katalogu.
4. Spróbuj dać 'w+' albo 'a+' w fopen to zobaczysz gdzie Ci ten plik utworzy i jakoś się umiejscowisz ze swoim skryptem.

Ten post edytował JoShiMa 1.09.2008, 12:56:49


--------------------
Go to the top of the page
+Quote Post
nortalf
post 1.09.2008, 13:02:07
Post #6





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.09.2008

Ostrzeżenie: (0%)
-----


Ciekawa sprawa ale tworzy pliku save.txt po zmianie na 'w+'. Nie ma go w żadnym z podkatalogów i katalogu głównym ze skryptem.
Go to the top of the page
+Quote Post
Cysiaczek
post 1.09.2008, 13:42:08
Post #7





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Opiekun o coś prosił - teraz to się skontaktujesz na PW z którymś moderatorem i obiecasz, że się będziesz stosował do próśb ekipy porządkowej.
Zamykam


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post

Closed TopicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 8.07.2025 - 05:10