-->-->-->-->-->-->-->-->-->-->-->-->-->
$bNewFile = false; //--
$sFilePath = ''; //-- the name and full path to the text file
$sFileContents = ''; //-- the contents of the text file
$aaTextLines = ''; //--
$iBackups = 4; //-- the number of backup files to create
$sFilePath = $_POST['saveFilePath'];
$sFilePathEncoded = htmlspecialchars($sFilePath);
$sFilePathUrlEncoded = htmlspecialchars(urlencode($sFilePath));
$sCurrentDirectory = dirname($sFilePath);
$sCurrentWebDirectory =
str_replace('/usr50/home/retrovox/public_html', '', $sCurrentDirectory);
$sFileContents = $_POST['fileContents'];
//-- This is the base-name for the backup files
$sBackupFileBaseName = preg_replace("/\..*$/", "-old", $sFilePath);
if ($sFilePath == '')
{
echo "
Retrovox Notepad, (No file name specified)
No file name specified
You did not specify any file to be edited.
This may indicate that the script retrovox-notepad.php
is not working correctly.
Or it may indicate that you have typed the address of this
page directly in your web-browser rather than arriving here after
submiting the form in the script retrovox-notepad.php
";
exit;
} //-- if no file specified
if (!is_writable($sFilePath))
{
echo "
Retrovox Notepad, (File is not writable)
The file is not writable
The file-name \"$sFilePathEncoded\" has its permissions
set so that is cannot be edited (updated or modified in any way).
You may be able to overcome this problem by typing
chmod a+w $sFilePath
when you are logged into the Retrovox server.
This message may indicate that the script retrovox-notepad.php is not
working properly. No changes to the text file have been saved.
";
return;
}
//-- if file not writeable
if (is_dir($sFilePath))
{
echo "
Retrovox Notepad, (The path is a directory)
The path is a directory
The file-name \"$sFilePathEncoded\" for the file which you
have been editing is a directory (folder). This probably indicates
that the script retrovox-notepad.php or retrovox-notepad-new.php
is not working properly.
The Retrovox Notepad system is for editing text files located on the
server.
Re-enter the file name
";
return;
} //-- if file is a directory
if (file_exists($sFilePath))
{
for ($ii = $iBackups; $ii > 0; $ii--)
{
$sNewName = "$sBackupFileBaseName$ii.txt";
$sOldName = "$sBackupFileBaseName".($ii-1).".txt";
if (file_exists($sOldName))
{
rename($sOldName, $sNewName);
} //-- if
} //-- for
rename($sFilePath, $sBackupFileBaseName."1.txt");
//unlink($sFilePath);
} //-- if file exists
//-- save the changes
$fileHandler = fopen($sFilePath, "w");
fwrite($fileHandler, stripslashes($sFileContents));
fclose($fileHandler);
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>
Retrovox Notepad (File changes saved)
The file has been saved:
The changes which you made to the text file =$sFilePathEncoded?>
have been saved.
-->-->-->-->-->-->-->-->-->-->-->-->-->
echo "
The following backup files for this text file currently exist