首页 > 编程技术 > php

php简单文件下载过滤判断函数

发布时间:2016-11-25 15:13

php简单文件下载过滤判断函数

if(strpos($fileurl, ':/'))//远程文件
{
 header("Location: $fileurl");
}
else//本地文件
{
 if($d == 0)
 {
  header("Location: ".SITE_URL.$fileurl);
 }
 else
 {
  $fileurl = file_exists($fileurl) ? stripslashes($fileurl) : PHPCMS_ROOT.$fileurl;//此处可能为物理路径
  $filename = basename($fileurl);
  if(preg_match("/^([sS]*?)([x81-xfe][x40-xfe])([sS]*?)/", $fileurl))//处理中文文件
  {
   $filename = str_replace(array("%5C", "%2F", "%3A"), array("\", "/", ":"), urlencode($fileurl));
   $filename = urldecode(basename($filename));
  }
  file_down($fileurl, $filename);
 }
}

php 生成验证码源码


session_start();

$enablegd = 1;
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
 if(!function_exists($func))
 {
  $enablegd = 0;
  break;
 }
}

ob_clean();

if($enablegd)
{
 //create captcha
 $consts = 'cdfgkmnpqrstwxyz23456';
 $vowels = 'aek23456789';
 for ($x = 0; $x < 6; $x++)
 {
  $const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1);
  $vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1);
 }
 $radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
 $_SESSION['checkcode'] = $string = substr($radomstring,0,4); //only display 4 str
 //set up image, the first number is the width and the second is the height
 $imageX = strlen($radomstring)*8; //the image width
 $imageY = 20;      //the image height
 $im = imagecreatetruecolor($imageX,$imageY);

 //creates two variables to store color
 $background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250));
 $foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
         imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
         imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
         imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255)));
 $foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80);
 $middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160));
 $middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80);

 //fill image with bgcolor
 imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
 //writes string
 imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[0]);
 imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
 imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/ALGER.TTF', $string[2]);
 imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], PHPCMS_ROOT.'include/fonts/arial.ttf', $string[3]);
 
 //strikethrough

 $border = imagecolorallocate($im, 133, 153, 193);
 //imagefilledrectangle($aimg, 0, 0, $x_size - 1, $y_size - 1, $back);
 imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);

 $pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
 for ($i=0;$i<80;$i++)
 {
  imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
 }
 //random shapes
 for ($x=0; $x<9;$x++)
 {
  if(mt_rand(0,$x)%2==0)
  {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
   imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2);
  }
  else
  {
   imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
   imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
  }
 }
 //output to browser
    header("content-type:image/pngrn");
 imagepng($im);
 imagedestroy($im);
}
else
{
 $files = glob(PHPCMS_ROOT.'images/checkcode/*.jpg');
 if(!is_array($files)) exit($LANG['please_check_dir_images_checkcode']);

 $checkcodefile = $files[rand(0, count($files)-1)];
 $_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4);

 header("content-type:image/jpegrn");
 include $checkcodefile;
}

php imagecreate图片生成代码


if(isset($gd) && $gd==1 && $txt)
{
 header ("Content-type: image/png");
 $txt = urldecode(phpcms_auth($txt, 'DECODE', AUTH_KEY));
 $imageX = strlen($txt)*9;
 $im = @imagecreate ($imageX, 16) or die ("Cannot Initialize new GD image stream");
 $bgColor = ImageColorAllocate($im,255,255,255);
 $white=imagecolorallocate($im,234,185,95);
 $font_color=imagecolorallocate($im,0x00,0x00,0x00);
 
 $fontfile = PHPCMS_ROOT."include/fonts/simfang.ttf";
 if(file_exists($fontfile) && !preg_match('/([a-z0-9@.])/',$txt))
 {
  $txt = iconv("GB2312","UTF-8",$txt);
  ImageTTFText($im, 10, 0, 0, 12, $font_color, $fontfile, $txt);
 }
 else
 {
  $fonttype = intval($fonttype);
  imagestring ($im, $fonttype, 0, 0,$txt, $font_color);
 }
 imagepng ($im);
 imagedestroy ($im);
}

php 常用获取服务器变量代码


define('IP', ip());
define('HTTP_REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
define('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : preg_replace("/(.*).php(.*)/i", "\1.php", $_SERVER['PHP_SELF']));
define('QUERY_STRING', $_SERVER['QUERY_STRING']);
define('PATH_INFO', isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '');
define('DOMAIN', isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : preg_replace("/([^:]*)[:0-9]*/i", "\1", $_SERVER['HTTP_HOST']));
define('SCHEME', $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
define('SITE_URL', SCHEME.$_SERVER['HTTP_HOST'].PHPCMS_PATH);
define('RELATE_URL', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : SCRIPT_NAME.(QUERY_STRING ? '?'.QUERY_STRING : PATH_INFO));
define('URL', SCHEME.$_SERVER['HTTP_HOST'].RELATE_URL);
define('RELATE_REFERER',urlencode(RELATE_URL));

mysql 查询数据库返回mysql_num_rows记录


 function getCityId( $cd )
 {
  $sql = "Select id,cntitle from zgy_classplace where cntitle='$cd' ";
  $result  = mysql_query( $sql ) or die( mysql_error());
  if( mysql_num_rows($result ) )
  {
   $rs = mysql_fetch_array( $result );
   return $rs['id'];
  }
  else
  {
   return 1;
  }
  mysql_free_result( $result );
 }

本站原创转载注明来自www.111cn.net/phper/php.html

标签:[!--infotagslink--]

您可能感兴趣的文章: