/** * 存储函数 * * @access public * @param string $url * @param string $data * @return void **/ public function save($url, $data) { if (!$url || !$data) { return false; } $url = trim($url, '/'); $first = stripos($url, '/'); $end = strripos($url, '/'); $tmp_url = $url; $last = 'index'; if (!($first == $end || $first == $end - 1)) { $last = strrchr($url, '/'); if ($last && strpos($last, '.')) { $tmp_url = substr($url, 0, $end); } } preg_match('/http:\\/\\/([^\\/]+)[\\/]?([a-zA-Z0-9\\/]*)/i', $tmp_url, $match); if (!$match) { return false; } $store = Loader::load_config('store'); $sub = isset($match[2]) && $match[2] ? $match[2] : ''; $sub = $sub ? trim($sub, '/') . '/' : ''; $path = $store['save_path'] . trim($match[1], '/') . '/' . $sub; $file = $path . trim($last, '/'); $content = is_object($data) ? $data->results : $data; check_path($path, 0777); @file_put_contents($file, serialize($content)); //务必调用否则不能触发解析程序 push_to_parser($url, $file); }
function check_path($path, $mode = 0755) { if (!is_dir($path)) { check_path(dirname($path), $mode); } return @mkdir($path, $mode); }
/** * Thư mục 'storage' của user * Khi có lỗi, $ignore_error = * - true: return [eror code, message] * - false: dừng app bằng 'abort' * * @param string $path * @param bool $ignore_error * @param int|null $id * * @return string|array */ function user_storage_path($path = '', $ignore_error = false, $id = null) { if ($username = user('username', $id)) { $path = storage_path("data/{$username}" . ($path ? "/{$path}" : '')); return check_path($path, $ignore_error, $path); } else { return response_error(3, 'Not call user_storage_path() for Guest', $ignore_error); } }
function check_htaccess($htaccess_string) { $x = check_path('../.htaccess'); if ($x['exists'] === false) { $message .= '<p>Missing .htaccess file</p>' . "\n"; $status = 'error'; } else { $message .= '<p>Found the .htaccess file</p>' . "\n"; $status = 'aok'; } return array('message' => $message, 'status' => $status); }
/** * @param $path string Path to a folder to search * recurce searching. Warring! may be stackoverflow on deep tree! to protect may limited call stack size. */ function treeScan($path) { if (check_path($path)) { $dir = @scandir($path); foreach ($dir as $dirname) { if ($dirname == '.' or $dirname == '..') { continue; } if (check_path($path . DIRECTORY_SEPARATOR . $dirname)) { treeScan($path . DIRECTORY_SEPARATOR . $dirname); //bad desigion. may be stack overflow. } else { add_file($path . DIRECTORY_SEPARATOR . $dirname); } } } }
# init $destination = $to = $_POST['destination']; $file = $_POST['file']; $me = _basename($file); if ($destination == '/') { $destination = ''; } if ($file == '/') { $file = ''; } if ($file[0] == '/') { $file = substr($file, 1); } $file_with_path = $_SESSION['upload_root_path'] . $_SESSION['upload_user_path'] . $file; $destination = $_SESSION['upload_root_path'] . $_SESSION['upload_user_path'] . $destination; if (check_path($file) && check_path($destination)) { if (is_file($file_with_path)) { $file = $file_with_path; } $file = $file_with_path; $file = stripslashes($file); $destination_temp = addslash_if_needed($destination) . _basename($file); # if file/folder exists in destination folder, change name if (is_file($destination_temp) || is_dir($destination_temp)) { $destination_temp = addslash_if_needed($destination) . rename_item(_basename($file), $destination); } $destination = $destination_temp; if (!is_dir(dirname('thumbs/' . $destination))) { mkdir(dirname('thumbs/' . $destination), 0744, true); } @rename(get_thumbs_name($file_with_path), get_thumbs_name($destination));
<?php defined('SYSPATH') or die('No direct access allowed.'); function check_path($path) { if (is_dir($path)) { return "pass"; } else { return "fail"; } } function check_cache($path) { if (is_writable($path)) { return true; } else { return false; } } $page = "\n\t\t<!DOCTYPE html>\n\t\t<head>\n\t\t<title>Install Check | CSScaffold</title>\n\t\t<style>\n\t\t\t.pass { color:green; }\n\t\t\t.fail { color:red; }\n\t\t\thtml { background:#e7e7e7; }\n\t\t\t.content { width:70%; margin:30px auto; font:15px/18px Arial; padding:20px; background:#fff; color:#595959; border:1px solid #aaa; margin-bottom: 20px; }\n\t\t\tdl { border-top:1px solid #eee; padding-top:20px }\n\t\t</style>\n\t\t</head>\n\t\t<body>\n\t\t\t<div class='content'>\n\t\t\t<h1>Installation</h1>\n\t\t\t<p>Make sure you remove install.php when you're finished.</p>\n\t\t\t\t<dl>\n\t\t\t\t\t<dt>Document Root</dt>\n\t\t\t\t\t<dd class='" . check_path(DOCROOT) . "'>" . DOCROOT . "</dd>\n\t\t\n\t\t\t\t\t<dt>System Path</dt>\n\t\t\t\t\t<dd class='" . check_path(SYSPATH) . "'>" . SYSPATH . "</dd>\n\t\t\n\t\t\t\t\t<dt>CSS Path</dt>\n\t\t\t\t\t<dd class='" . check_path(CSSPATH) . "'>" . CSSPATH . "</dd>\n\t\t\t\t\t\n\t\t\t\t\t<dt>Path to Scaffold folder</dt>\n\t\t\t\t\t<dd class='" . check_path(SCAFFOLD) . "'>" . SCAFFOLD . "</dd>\n\t\t\t\t\t\n\t\t\t\t\t<dt>Plugins Path</dt>\n\t\t\t\t\t<dd class='" . check_path(PLUGINS) . "'>" . PLUGINS . "</dd>\n\t\t\t\t\t\n\t\t\t\t\t<dt>Cache Path</dt>\n\t\t\t\t\t<dd class='" . check_path(CACHEPATH) . "'>" . CACHEPATH . "</dd>\t\t\t\t\t\n\t\t\n\t\t\t\t</dl>\n\t\t\t\t\t\n\t\t\t</div>\n\t\t</body>\n\t\t</html>\n\t\t"; echo $page;
function fileinfo($file) { $code = OK; $res = ""; if (!check_path($file)) { $code = E_PATH_RESTRICTION; } else { if (is_dir($file)) { $res = $file . ": directory"; } else { switch (pathinfo($file, PATHINFO_EXTENSION)) { case "txt": $res = $file . ": ASCII text"; break; /* working on it... */ /* working on it... */ default: $res = ""; } } } return array($code, $res); }
function processMap($filename) { global $FORCE_CREATE, $DEBUG; global $zoomFactor; $mrsid_base_name = basename($filename); //"S-50-20"; // $mrsid_file=$mrsid_base_name."/".$mrsid_base_name.".sid"; $mrsid_file = $filename . ".sid"; // system("tar xf ".$mrsid_base_name.".tar"); ob_start(); system("./mrsidinfo {$mrsid_file}"); $res_str = ob_get_contents(); ob_end_clean(); $lines = explode("\n", $res_str); // we need the following info // format: MRSID // width: 27717 // height: 22140 // X UL: 73986.000000 // Y UL: -2138298.000000 // X res: 28.500000 // Y res: -28.500000 foreach ($lines as $line) { //echo $line."<BR>"; if (preg_match("/format:(.*)/i", $line, $matches)) { $format = trim($matches[1]); } else { if (preg_match("/width:(.*)/i", $line, $matches)) { $tot_width = trim($matches[1]) + 0; } else { if (preg_match("/height:(.*)/i", $line, $matches)) { $tot_height = trim($matches[1]) + 0; } else { if (preg_match("/X UL:(.*)/i", $line, $matches)) { $X_UL = trim($matches[1]) + 0; } else { if (preg_match("/Y UL:(.*)/i", $line, $matches)) { $Y_UL = trim($matches[1]) + 0; } else { if (preg_match("/X res:(.*)/i", $line, $matches)) { $Xresolution = trim($matches[1]) + 0; } else { if (preg_match("/Y res:(.*)/i", $line, $matches)) { $Yresolution = trim($matches[1]) + 0; } } } } } } } } if ($format != "MRSID") { echo "Not a Mrsid file\n"; return; } $parts = explode("-", $mrsid_base_name); $UTMzone = $parts[1]; $hemisphere = strtolower($parts[0]); if (($pos = strpos($parts[2], "_")) === false) { $UTMzoneY = $parts[2]; } else { $UTMzoneY = substr($parts[2], 0, $pos); } if ($DEBUG) { echo "UTMzone = {$UTMzone} \n"; echo "UTMzoneY = {$UTMzoneY} \n"; echo "hemisphere= {$hemisphere}<br>\n"; echo "tot_width = {$tot_width} \n"; echo "tot_height = {$tot_height}<br>\n"; echo "X_UL = {$X_UL} \n"; echo "Y_UL = {$Y_UL}<br>\n"; echo "Xresolution = {$Xresolution} \n"; echo "Yresolution = {$Yresolution}<br>\n"; } // 2048 max pixels per tile $X_tiles_num = ceil($tot_width / 2048); $Y_tiles_num = ceil($tot_height / 2048); $tiles_width = floor($tot_width / $X_tiles_num); $tiles_height = floor($tot_height / $Y_tiles_num); $last_X_tiles_width = $tot_width - ($X_tiles_num - 1) * $tiles_width; $last_Y_tiles_height = $tot_height - ($Y_tiles_num - 1) * $tiles_height; if ($DEBUG) { echo "<hr>\n"; echo "X_tiles_num = {$X_tiles_num} \n"; echo "Y_tiles_num = {$Y_tiles_num} <br>\n"; echo "tiles_width = {$tiles_width} \n"; echo "tiles_height = {$tiles_height} <br>\n"; echo "last_X_tiles_width = {$last_X_tiles_width} \n"; echo "last_Y_tiles_height = {$last_Y_tiles_height}<br>\n"; echo "<HR>\n"; } $Xzoomed_resolution = $Xresolution * $zoomFactor; $res_str = str_replace(".", "_", str_replace(",", "_", abs($Xzoomed_resolution))); $dir_prefix = "mrsid_tiles/" . $res_str . "/UTM" . trim($UTMzone) . "/" . trim($UTMzoneY) . $hemisphere . "/"; $filename_prefix = strtoupper($hemisphere) . "-" . trim($UTMzone) . "-" . trim($UTMzoneY) . "_"; if ($DEBUG) { echo "PREFIX = " . $dir_prefix . $filename_prefix . "<BR>\n"; } check_path($dir_prefix); // $X_tiles_num=1; // $Y_tiles_num=1; for ($x = 0; $x < $X_tiles_num; $x++) { for ($y = 0; $y < $Y_tiles_num; $y++) { $filename_base = sprintf("%s%s%03d_%03d", $dir_prefix, $filename_prefix, $x, $y); $jpg_filename = $filename_base . ".jpg"; $tab_filename = $filename_base . ".tab"; if (!$FORCE_CREATE && file_exists($jpg_filename) && file_exists($tab_filename)) { continue; } if ($x < $X_tiles_num - 1) { $this_tile_width = $tiles_width; } else { $this_tile_width = $last_X_tiles_width; } if ($y < $Y_tiles_num - 1) { $this_tile_height = $tiles_height; } else { $this_tile_height = $last_Y_tiles_height; } $this_UL_x = $X_UL + $x * $tiles_width * $Xresolution; $this_UL_y = $Y_UL + $y * $tiles_height * $Yresolution; $this_UL_pixels_x = $x * $tiles_width; $this_UL_pixels_y = $y * $tiles_height; $this_tile_width_zoomed = floor($this_tile_width / $zoomFactor); $this_tile_height_zoomed = floor($this_tile_height / $zoomFactor); $this_UL_pixels_x_zoomed = floor($this_UL_pixels_x / $zoomFactor); $this_UL_pixels_y_zoomed = floor($this_UL_pixels_y / $zoomFactor); //echo $filename_base." ($this_UL_x , $this_UL_y) ".$this_tile_width."x".$this_tile_height." <BR>"; if ($zoomFactor < 8) { $z = $zoomFactor / 2; } else { if ($zoomFactor == 8) { $z = 3; } else { if ($zoomFactor == 16) { $z = 4; } else { if ($zoomFactor == 32) { $z = 5; } } } } $cmd_str = "./mrsiddecode -quiet -wf -s {$z} -i {$mrsid_file} -o {$jpg_filename} -ulxy {$this_UL_pixels_x_zoomed} {$this_UL_pixels_y_zoomed} -wh {$this_tile_width_zoomed} {$this_tile_height_zoomed}"; // echo "$cmd_str <br>"; system($cmd_str); make_tab_file($tab_filename, $jpg_filename, $this_UL_x, $this_UL_y, $this_tile_width, $this_tile_height, $Xresolution, $Yresolution); } } }
check_config_file_templates($_SESSION["settings"]["classes.csv"]); //"config/classes.csv"); check_config_file_templates($_SESSION["settings"]["passwd_list.txt"]); //"config/passwd_list.txt"); check_config_file_templates($_SESSION["settings"]["tan_config.txt"]); //"config/tan_config.txt"); check_config_file_templates($_SESSION["settings"]["tan_list.txt"]); //"config/tan_list.txt"); check_config_file_templates($_SESSION["settings"]["tan_used.txt"]); //"config/tan_used.txt"); check_config_file_templates("admin/layout_ausweis.html"); check_config_file_templates("admin/layout_klasse.html"); check_path("images_school_classes"); check_path("temp_image_file_path"); check_path("target_image_file_path"); check_path("images_matching_lisa"); } //preecho($_SESSION["settings"]); //System auf UTF-8 einstellen if (function_exists('iconv') && PHP_VERSION_ID < 50600) { //Older PHP Version iconv_set_encoding("input_encoding", $_SESSION["settings"]["character_encoding"]); iconv_set_encoding("internal_encoding", $_SESSION["settings"]["character_encoding"]); iconv_set_encoding("output_encoding", $_SESSION["settings"]["character_encoding"]); } elseif (PHP_VERSION_ID >= 50600) { ini_set("default_charset", $_SESSION["settings"]["character_encoding"]); } //Anzeige von PHP-Fehlern if (isset($_SESSION["settings"]["php_error_reporting"])) { if ($_SESSION["settings"]["php_error_reporting"] == true) { error_reporting(E_ALL);