Con PHP è più facile di quanto si possa pensare scrivere files di testo sul server......
Codice PHP:
$handle = fopen("file.txt", "w");
fwrite($handle, "Testo che vuoi scrivere nel file di testo...");
fclose($handle);
Ora che mi viene in mente, avevo scritto anche una funzioncina per aggiungere dati a un file di testo esistente, scegliendo se inserirli in cima o in fondo. Te la posto.
Codice PHP:
function AddToFile($filepath, $text, $position)
{
if (file_exists($filepath) == false)
{
if ($filepath == "") echo("AddToFile() ERROR: Non è stato inserito il percorso (filepath) del file da modificare!");
else echo("AddToFile() ERROR: Il file \"$filepath\" non esiste sul server.");
return false;
}
if ($position == "b")
{
$file_handle = fopen($filepath, "r+");
$data = fread($file_handle, filesize($filepath));
fclose($file_handle);
$temptext = "$text\n$data";
}
else if ($position == "e")
{
$file_handle = fopen($filepath, "a+");
$data = fread($file_handle, filesize($filepath));
fclose($file_handle);
$temptext = "$data\n$text";
}
$file_handle = fopen($filepath, "w");
if (fwrite($file_handle, $temptext) == false) return false;
fclose($file_handle);
return true;
}
Uso:
Codice PHP:
$Nick = $_POST['Nickname'];
$Msg = $_POST['Messaggio'];
$path = "guestbook.txt"; // Percorso del file di testo da modificare
$Messaggio = date("d/m/Y")." ".date("G:i:s")." ".$Nick." ~ ".$Msg."\n"; // Messaggio da aggiungere
if (AddToFile($path, $Messaggio, "b")) // Prova ad aggiungere il testo in cima al file
echo("Il tuo commento è stato salvato");
else echo("Il tuo commento non è stato salvato in seguito a un errore tecnico.");