PHP程式碼片段記錄

flowerszhong發表於2016-10-30

檢查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);


相關文章