Пример #1
0
 /**
  * 取小数点后一位小数,根据第二位进行4舍5入(用于计算总评)
  */
 function get_float($num)
 {
     if (ceil($num) == $num) {
         return $num;
     } else {
         $num = explode(".", $num);
         if (fn_function::my_substr_00($num[1], 2, 0) % 10 >= 5) {
             $num[0] = $num[0] . "." . (fn_function::my_substr_00($num[1], 1, 0) + 1);
         } else {
             $num[0] = $num[0] . "." . fn_function::my_substr_00($num[1], 1, 0);
         }
         return $num[0];
     }
 }
Пример #2
0
 function upload_image()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         //check the iamge is exist
         if (!is_uploaded_file($_FILES["upfile"]["tmp_name"])) {
             return $img_unfind = fn_function::alert_msg('图片不存在!');
             exit;
         }
         $file = $_FILES["upfile"];
         //check the iamge's size
         if ($this->max_file_size < $file["size"]) {
             return $img_side_too_big = fn_function::alert_msg('图片大小超过系统允许最大值!');
             exit;
         }
         //check the iamge's type
         if (!in_array($file["type"], $this->up_img_types)) {
             return $img_type = fn_function::alert_msg('图片类型不符!');
             exit;
         }
         if (!file_exists($this->destination_folder)) {
             if (!fn_function::mkdirs($this->destination_folder)) {
                 return $mkdir_warry = fn_function::alert_msg('目录创建失败!');
                 exit;
             }
         }
         $file_name = $file["tmp_name"];
         $image_size = getimagesize($file_name);
         $pinfo = pathinfo($file["name"]);
         $file_type = $pinfo['extension'];
         $destination = $this->destination_folder . time() . "." . $file_type;
         setcookie($this->cookie_set, $destination);
         if ($image_size[0] > $this->max_image_side || $image_size[1] > $this->max_image_side) {
             return $img_side_too_big = fn_function::alert_msg('图片分辨率超过系统允许最大值!');
             exit;
         }
         $overwrite = "";
         if (file_exists($destination) && $overwrite != true) {
             return $img_exist = fn_function::alert_msg('同名文件已经存在了!');
             exit;
         }
         if (!move_uploaded_file($file_name, $destination)) {
             return $img_move = fn_function::alert_msg('移动文件出错!');
             exit;
         }
         $img_upload_sucess = "<font color=red face=微软雅黑>上传成功</font><br>";
         if ($this->img_preview == 1) {
             $img_src = "<img src=\"" . $destination . "\" width=" . $image_size[0] * $this->img_preview_size . " height=" . $image_size[1] * $this->img_preview_size;
             $img_upload_sucess .= $img_src;
         }
         return $img_upload_sucess;
     }
 }