PHP 代码片段记录

检查URL是否为图片地址 getimagesize()

Function check_img($file) {

   $x = getimagesize($file);

   switch ($x['mime']) {
      case "image/gif":
         $response = 'this is a gif image.';
         break;
      case "image/jpeg":
         $response = 'this is a jpeg image.';
         break;
      case "image/png":
         $response = 'this is a png image.';
         break;
      default:
         $response = 'This is not a image file.';
         break;
   }

   return $response;    
}

echo check_img('http://www.example.com/image.jpg');

页面跳转

function Redirect($url, $permanent = false)
{
    if (headers_sent() === false)
    {
        header('Location: ' . $url, true, ($permanent === true) ? 301 : 302);
    }

    exit();
}

Redirect('http://www.google.com/', false);
上一篇:逻辑代码自动生成相关技术概述


下一篇:百花开放笑声甜,“开源萌宠”庆六一