+++ /dev/null
-<?php\r
-class TxtFileTools\r
-{\r
-\r
-\r
- /**\r
- * Saves a String into a file and return the file URL\r
- *\r
- * @param String $theFileName The file Name\r
- * @param String $theString The value to save as a String\r
- * @return String $fullFileUrl The full path of where file is saved \r
- */\r
- static public function stringToFile($theFileName, $theString) \r
- {\r
- global $rosettaCCSettings;\r
- \r
- $fullFileUrl = $rosettaCCSettings['uploadDir'].'/'.$theFileName;\r
- \r
- // save file to disk \r
- file_put_contents($fullFileUrl, $theString);\r
- \r
- //echo '<br/><br/>Target Caption File saved in: <b>'.$theFileName.'</b> <a href="'.$fullFileUrl.'"> [Download Caption]</a>';\r
- \r
- return $fullFileUrl;\r
- \r
- } // stringToFile\r
-\r
- /**\r
- * Loads a Caption File and return it as String\r
- * @param $theFileName The full URL of the file\r
- * @return $ccString The caption file as String\r
- */\r
- static public function fileToString($theFileName) \r
- {\r
- global $rosettaCCSettings;\r
- \r
- $ccString = file_get_contents($rosettaCCSettings['uploadDir'].'/'.$theFileName);\r
- \r
- /*\r
- clean malformed pattern for ANSI files:\r
- This is harmless for any well formed caption.\r
- fixing captions saved in win notepad\r
- */\r
- $toSearch = array(chr(13).chr(10));\r
- $toReplace = array(chr(10));\r
- $contents = str_replace($toSearch,$toReplace,$ccString);\r
- \r
- return $ccString;\r
- } \r
-\r
- /**\r
- * Forces a browser to download a file stored in the server \r
- * @param $exfile The full URL of the file\r
- */\r
- static public function downloadFile($exfile) \r
- {\r
- // verify if the file exists\r
- if (file_exists($exfile)) \r
- {\r
- header('Content-Description: File Transfer');\r
- header('Content-Type: application/octet-stream');\r
- header('Content-Disposition: attachment; filename='.basename($exfile));\r
- header('Content-Transfer-Encoding: binary');\r
- header('Expires: 0');\r
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');\r
- header('Pragma: public');\r
- header('Content-Length: ' . filesize($exfile));\r
- //header("Content-type: $type"); ????????\r
- ob_clean();\r
- flush();\r
- readfile($exfile);\r
- exit;\r
- \r
- } // end if\r
- \r
- } // end downloadFile() \r
-\r
- /**\r
- * Replaces all <br/> tags in a string with chr(10) characters\r
- *\r
- * @param String $theHtmlString The string containign <br> HTML tags \r
- * @return unknown\r
- */\r
- static public function ccBrToNewLine($theHtmlString)\r
- {\r
- $a = array(chr(10));\r
- $b = array('<br>','<BR>','<br/>','<BR/>' );\r
- $stringWithBreakLines = str_replace($a, $b, $theHtmlString);\r
- return $stringWithBreakLines;\r
- }\r
-\r
- /**\r
- * Replaces the break line character "char(10)" by a specified character \r
- *\r
- * @param String $theCaption The caption containing char(10) characters as line separators \r
- * @param char $theChar The String used to replace the break line character\r
- * @return unknown\r
- */static public function ccNewLineToBr($theCaption, $theChar)\r
- {\r
- $a = ''.chr(10);\r
- $b = $theChar;\r
- $newString = str_replace($a, $b, $theCaption);\r
- return $newString;\r
- }\r
- \r
-} // end class TxtFileTools\r
-?>
\ No newline at end of file