public function maxUploadSize() { return FileSystemUtils::humanFileSize(FileSystemUtils::iniValueInBytes(ini_get('upload_max_filesize'))); }
protected function deriveMetaDatatype(ValidationExpression $ve) { $v = $ve->getValidationArray(); $datatype = $v['datatype']; switch ($datatype) { case 'flag': return 'flag'; case 'boolean': return 'tiny'; case 'date': if (isset($v['unix']) && !StringUtils::strToBool($v['unix'])) { return 'datetime'; } // If unix attribute is not specified, assume they want date (timestamp) for backward-compatibility return 'date'; case 'int': $min = isset($v['min']) ? (int) $v['min'] : 0; $max = isset($v['max']) ? (int) $v['max'] : PHP_INT_MAX; if ($min < 0) { if ($min >= -128 && $max <= 127) { return 'tiny-signed'; } else { if ($min >= -2147483648 && $max <= 2147483647) { return 'int-signed'; } } return 'long-signed'; } if ($max < 255) { return 'tiny'; } else { if ($max <= 4294967295) { return 'int'; } } return 'long'; case 'float': return 'float'; case 'slug': case 'slugwithslash': case 'email': $ve->setMax(255); // set max return 'varchar'; case 'json': $ve->setMax(262144); //set max to 256K return 'mediumtext'; case 'string': case 'html': case 'url': // NOTE: MySQL columns are bytes, string lengths are characters $max = 255; // default is 255 if (isset($v['max'])) { $max = (int) FileSystemUtils::iniValueInBytes($v['max']); } if ($max == 65536) { $max = 65535; } if ($max > 262144) { // max is 256K $max = 262144; } $ve->setMax($max); // set max if ($max <= 255) { // 255 or less is VARCHAR return 'varchar'; } if ($max <= 65535) { // 64K or less is TEXT return 'text'; } if ($max <= 262144) { // 256K or less is MEDIUMTEXT return 'mediumtext'; } case 'binary': $max = 262144; // default is 256K if (isset($v['max'])) { $max = (int) FileSystemUtils::iniValueInBytes($v['max']); } if ($max == 65536) { $max = 65535; } if ($max > 262144) { // max is 256K $max = 262144; } $ve->setMax($max); // set max if ($max <= 65535) { // 64K or less, store as BLOB return 'blob'; } if ($max <= 262144) { // 256K or less, store as MEDIUMBLOB return 'mediumblob'; } } }
public function findBetween($filename, $startTag, $endTag) { $chunkSize = FileSystemUtils::iniValueInBytes($this->chunkSize); $fp = @fopen($filename, 'rb'); if (!$fp) { throw new BigFileException("Could not open file {$filename}"); } $output = null; $buf = ''; $startPos = false; $endPos = false; $error = null; for (;;) { // read $chunk = @fread($fp, $chunkSize); // check for error or eof if (empty($chunk)) { if (!feof($fp)) { $error = 'Read failure'; } else { if ($startPos !== false) { $error = 'Unterminated'; } else { $error = 'Not Found'; } } break; } $buf .= $chunk; if ($startPos === false) { // haven't found start of data yet $startPos = strpos($buf, $startTag); if ($startPos !== false) { $output = substr($buf, $startPos); $firstTry = true; $buf = ''; } else { $buf = substr($buf, 1 - strlen($startTag)); } } if ($startPos !== false) { // have found start of data $output .= $buf; $endPos = strpos($output, $endTag); if ($endPos !== false) { $output = substr($output, 0, $endPos + strlen($endTag)); break; } else { if ($firstTry) { $firstTry = false; $buf = ''; } else { $error = "Data exceeds limit of {$chunkSize} bytes"; break; } } } // END if we've found start of data } // END each chunk @fclose($fp); if ($error) { throw new BigFileException($error); } return $output; }