Hi Bravo,
Thanks for the answer, I'm trying it right now to see if it works...I'll edit this post with the results.
EDIT:
Ok, I've tried that...it didn't work. Here's the code that I have so far, hope it helps!
I have a file called rte.php which contain the wymeditor instance:
- Code: Select all
require_once("library.php");
$fileName = $_GET["file"];
$lang = $_GET["lang"];
//Set the full relative path
if ($lang == "en")
$filePath = "../includes/txt/";
else
$filePath = "../../fr/includes/txt/";
$fileToRead = $filePath . $fileName;
if (file_exists($fileToRead)) {
//Get the content of the file in a string
//file(strPath) returns an array of string, implode concatenate it back to a single string.
if ( $fileContent = implode('', file($fileToRead)) ){
//
}
else{
echo BuildErrorString($_SERVER['PHP_SELF'], "Error reading", true);
}
}
else {
echo BuildErrorString($_SERVER['PHP_SELF'], "The file does not exist", true);
}
THis correctly read the file passed as a parameter, I then load the string $fileContent in wymeditor and I see the file fine.
If I open a preview from wymeditor I see the special characters ok at this point. At the bottom there's a form submit which submit to the script writing to the file:
- Code: Select all
$filename = $_POST['filename'];
$fp = fopen( $filename, "w" );
if(!$fp)
{echo "Couldn't open the data file. Try again later.";
exit;}
$content = $_POST['txthtml'];
//echo $content;
fwrite( $fp, $content );
fclose( $fp );
header("Location: mg_text.php");
This also correctly write to the file and the special characters are in the file when I open it.
Now when I try going to the page which make use of the txt file it shows "garbage" characters instead.
I used to use a simple include(foobar.txt);
Then I tried as you suggested:
- Code: Select all
$filename = "includes/txt/contact.txt";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
This still shows "garbage" instead of the actual characters...
I'm kinda lost on this one...