/**
  * @Title: DefaultFilenameGen
  * @Description: todo(获取转移后的文件或者文件夹名称)
  * @param string $dst 文件路径
  * @param int $step 一个标志,true 代表文件夹,false 代表文件
  * @return string 返回一个转义后的文件或者文件夹名称
  * @author liminggang
  * @date 2013-8-20 下午2:49:35
  * @throws
  */
 function DefaultFilenameGen($dst, $step = 1)
 {
     $tmpdst = $dst;
     //文件夹
     if ($step) {
         while (true) {
             $info = pathinfo($dst);
             $dir = $info["dirname"];
             $name = $info["filename"];
             $tmp = md5($name);
             //用md5转义文件夹名称
             $rename = build_count_rand(1, 5, 1);
             $tmp = $rename[0];
             $tmpdst = $dir . "/" . $tmp;
             if (!file_exists($tmpdst)) {
                 break;
             }
         }
     } else {
         while (true) {
             $info = pathinfo($dst);
             $ext = $info["extension"];
             $dir = $info["dirname"];
             $name = $info["filename"];
             $rename = build_count_rand(1, 2, 1);
             $tmp = time() . "_" . $rename[0] . "." . $ext;
             //用时间戳转义文件名称
             $tmpdst = $dir . "/" . $tmp;
             if (!file_exists($tmpdst)) {
                 break;
             }
         }
     }
     return $tmp;
 }
Esempio n. 2
0
 /**
 +----------------------------------------------------------
 * 生成高级图像验证码
 +----------------------------------------------------------
 * @static
 * @access public 
 +----------------------------------------------------------
 * @param string $type 图像格式
 * @param string $width  宽度
 * @param string $height  高度
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 static function showAdvVerify($type = 'png', $width = 180, $height = 40)
 {
     $verifyCodeRandArray = build_count_rand(10, 1, 3);
     $i = 0;
     while (list($k, $v) = each($verifyCodeRandArray)) {
         $verifyCode[$i] = $v;
         $i++;
     }
     $letter = implode(" ", $verifyCode);
     $_SESSION['verifyCode'] = $verifyCode;
     $im = imagecreate($width, $height);
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     $key = mt_rand(0, 3);
     $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     $numberColor = imagecolorallocate($im, 255, rand(0, 100), rand(0, 100));
     $stringColor = imagecolorallocate($im, rand(0, 100), rand(0, 100), 255);
     // 添加干扰
     for ($i = 0; $i < 10; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     for ($i = 0; $i < 255; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
     }
     imagestring($im, 5, 5, 1, "0 1 2 3 4 5 6 7 8 9", $numberColor);
     imagestring($im, 5, 5, 20, $letter, $stringColor);
     Image::output($im, $type);
 }