İnternette buldum. Bari paylaşayım başkaları yararlanabilir.
---------
Formdan gelen verileri mail ile gönderebiliyor veya veritabanına yazdırabiliyoruz. Peki formdan gelen veriyi dosyaya yazdırmak istersek?
ihtiyacımız olan 3 temel dosya var: HTML form dosyası, PHP verileri dosyaya yazdırılacak dosya, verilerin yazdırılacağı dosya (örnekte .txt olacak)
örnekte 3 dosya da yanı dizinde olacak. Örneğin amacı, formdan gelen mail adreslerini maillistesi.txt dosyasında alt alta sıralamak. HTML form dosyasının içeriği en temel haliyle şöyle olmalı: [COLOR=#FF8000]<form action=[COLOR=#0000FF]"mailekle.php"[/COLOR] method=[COLOR=#0000FF]"post"[/COLOR]>[/COLOR]
E-posta: [COLOR=#FF8000]<input type=[COLOR=#0000FF]"textbox"[/COLOR] name=[COLOR=#0000FF]"email"[/COLOR] size=[COLOR=#0000FF]"30"[/COLOR]>[/COLOR]
[COLOR=#FF8000]<input type=[COLOR=#0000FF]"submit"[/COLOR] value=[COLOR=#0000FF]"kaydet"[/COLOR]>[/COLOR]
[COLOR=#FF8000]</form>[/COLOR]
action="mailekle.php" dediğimiz mailekle.php dosyasının içeriği: [COLOR=#0000BB][FONT=monospace]<?php
$dosya_adi [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"maillistesi.txt"[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$deger [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$_POST[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"email"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]];
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$yazilacak_deger [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$deger[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]\n"[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
if ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$deger[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) {
if (![/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]file_exists[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$dosya_adi[/FONT][/COLOR][COLOR=#007700][FONT=monospace])){
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]touch[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$dosya_adi[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]chmod[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$dosya_adi[/FONT][/COLOR][COLOR=#007700][FONT=monospace],[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0666[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
}
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$dosyaya_baglanti [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]fopen[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$dosya_adi[/FONT][/COLOR][COLOR=#007700][FONT=monospace],[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"a+"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
if (![/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]fwrite[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$dosyaya_baglanti[/FONT][/COLOR][COLOR=#007700][FONT=monospace],[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$yazilacak_deger[/FONT][/COLOR][COLOR=#007700][FONT=monospace])){
echo [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Dosyaya yazılamadı."[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
exit;
}
echo [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Tamamdır. Dosyaya bak >> <a href='maillistesi.txt'>maillistesi.txt</a>"[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
} else {
echo [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Dosyaya yazılamadı."[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
}
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR]