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);
posted @ 2016-10-30 20:19  码不能停  阅读(143)  评论(0编辑  收藏  举报