function dump($var, $echo = true, $label = null, $strict = true) { $label = $label === null ? '' : rtrim($label) . ' '; if (!$strict) { if (ini_get('html_errors')) { $output = print_r($var, true); $output = "<pre>" . $label . htmlspecialchars($output, ENT_QUOTES) . "</pre>"; } else { $output = $label . " : " . print_r($var, true); } } else { ob_start(); var_dump($var); $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace("/\\]\\=\\>\n(\\s+)/m", "] => ", $output); $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES, "GB2312") . '</pre>'; } } if ($echo) { echo $output; return null; } else { return $output; } }
/** * Save an uploaded file to a new location. * * @param mixed name of $_FILE input or array of upload data * @param string new filename * @param string new directory * @param integer chmod mask * @return string full path to new file */ public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0755) { // Load file data from FILES if not passed as array $file = is_array($file) ? $file : $_FILES[$file]; if ($filename === NULL) { // Use the default filename, with a timestamp pre-pended $filename = time() . $file['name']; } // Remove spaces from the filename $filename = preg_replace('/\\s+/', '_', $filename); if ($directory === NULL) { // Use the pre-configured upload directory $directory = WWW_ROOT . 'files/'; } // Make sure the directory ends with a slash $directory = rtrim($directory, '/') . '/'; if (!is_dir($directory)) { // Create the upload directory mkdir($directory, 0777, TRUE); } //if ( ! is_writable($directory)) //throw new exception; if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) { if ($chmod !== FALSE) { // Set permissions on filename chmod($filename, $chmod); } //$all_file_name = array(FILE_INFO => $filename); // Return new file path return $filename; } return FALSE; }
function convert_uudecode($string) { // Sanity check if (!is_scalar($string)) { user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING); return false; } if (strlen($string) < 8) { user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING); return false; } $decoded = ''; foreach (explode("\n", $string) as $line) { $c = count($bytes = unpack('c*', substr(trim($line), 1))); while ($c % 4) { $bytes[++$c] = 0; } foreach (array_chunk($bytes, 4) as $b) { $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20; $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20; $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20; $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20; $b0 <<= 2; $b0 |= $b1 >> 4 & 0x3; $b1 <<= 4; $b1 |= $b2 >> 2 & 0xf; $b2 <<= 6; $b2 |= $b3 & 0x3f; $decoded .= pack('c*', $b0, $b1, $b2); } } return rtrim($decoded, "