Fixing file upload params ($_FILES) normalization. Closes #75
[akelos.git] / vendor / domit / php_file_utilities.php
blob658ccf31c3b7285c9d19876cf6f930bfe0b440ec
1 <?php
3 if (!defined('PHP_TEXT_CACHE_INCLUDE_PATH')) {
4 define('PHP_TEXT_CACHE_INCLUDE_PATH', (dirname(__FILE__) . "/"));
7 class php_file_utilities {
8 /**
9 * Retrieves binary or text data from the specified file
10 * @param string The file path
11 * @param string The attributes for the read operation ('r' or 'rb')
12 * @return mixed he text or binary data contained in the file
14 function &getDataFromFile($filename, $readAttributes, $readSize = 8192) {
15 $fileContents = null;
16 $fileHandle = @fopen($filename, $readAttributes);
18 if($fileHandle){
19 do {
20 $data = fread($fileHandle, $readSize);
22 if (strlen($data) == 0) {
23 break;
26 $fileContents .= $data;
27 } while (true);
29 fclose($fileHandle);
32 return $fileContents;
33 } //getDataFromFile
35 /**
36 * Writes the specified binary or text data to a file
37 * @param string The file path
38 * @param mixed The data to be written
39 * @param string The attributes for the write operation ('w' or 'wb')
41 function putDataToFile($fileName, &$data, $writeAttributes) {
42 $fileHandle = @fopen($fileName, $writeAttributes);
43 if ($fileHandle) {
44 fwrite($fileHandle, $data);
45 fclose($fileHandle);
47 } //putDataToFile
48 } //php_file_utilities