7 * Saves a String into a file and return the file URL
\r
9 * @param String $theFileName The file Name
\r
10 * @param String $theString The value to save as a String
\r
11 * @return String $fullFileUrl The full path of where file is saved
\r
13 static public function stringToFile($theFileName, $theString)
\r
15 global $rosettaCCSettings;
\r
17 $fullFileUrl = $rosettaCCSettings['uploadDir'].'/'.$theFileName;
\r
19 // save file to disk
\r
20 file_put_contents($fullFileUrl, $theString);
\r
22 //echo '<br/><br/>Target Caption File saved in: <b>'.$theFileName.'</b> <a href="'.$fullFileUrl.'"> [Download Caption]</a>';
\r
24 return $fullFileUrl;
\r
29 * Loads a Caption File and return it as String
\r
30 * @param $theFileName The full URL of the file
\r
31 * @return $ccString The caption file as String
\r
33 static public function fileToString($theFileName)
\r
35 global $rosettaCCSettings;
\r
37 $ccString = file_get_contents($rosettaCCSettings['uploadDir'].'/'.$theFileName);
\r
40 clean malformed pattern for ANSI files:
\r
41 This is harmless for any well formed caption.
\r
42 fixing captions saved in win notepad
\r
44 $toSearch = array(chr(13).chr(10));
\r
45 $toReplace = array(chr(10));
\r
46 $contents = str_replace($toSearch,$toReplace,$ccString);
\r
52 * Forces a browser to download a file stored in the server
\r
53 * @param $exfile The full URL of the file
\r
55 static public function downloadFile($exfile)
\r
57 // verify if the file exists
\r
58 if (file_exists($exfile))
\r
60 header('Content-Description: File Transfer');
\r
61 header('Content-Type: application/octet-stream');
\r
62 header('Content-Disposition: attachment; filename='.basename($exfile));
\r
63 header('Content-Transfer-Encoding: binary');
\r
64 header('Expires: 0');
\r
65 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
\r
66 header('Pragma: public');
\r
67 header('Content-Length: ' . filesize($exfile));
\r
68 //header("Content-type: $type"); ????????
\r
76 } // end downloadFile()
\r
79 * Replaces all <br/> tags in a string with chr(10) characters
\r
81 * @param String $theHtmlString The string containign <br> HTML tags
\r
84 static public function ccBrToNewLine($theHtmlString)
\r
86 $a = array(chr(10));
\r
87 $b = array('<br>','<BR>','<br/>','<BR/>' );
\r
88 $stringWithBreakLines = str_replace($a, $b, $theHtmlString);
\r
89 return $stringWithBreakLines;
\r
93 * Replaces the break line character "char(10)" by a specified character
\r
95 * @param String $theCaption The caption containing char(10) characters as line separators
\r
96 * @param char $theChar The String used to replace the break line character
\r
98 */static public function ccNewLineToBr($theCaption, $theChar)
\r
102 $newString = str_replace($a, $b, $theCaption);
\r
106 } // end class TxtFileTools
\r