Home  >  Article  >  Backend Development  >  Multiple examples of php getimagesize detecting the size of uploaded images

Multiple examples of php getimagesize detecting the size of uploaded images

WBOY
WBOYOriginal
2016-07-25 08:52:321046browse
  1. function CheckImageSize($ImageFileName,$LimitSize)
  2. {
  3. $size=GetImageSize($ImageFileName);
  4. if ($size[0]>$LimitSize[0]||$size[1]> $LimitSize[1]){
  5. echo 'Sorry, the size of the image you want to upload is too large';
  6. return false;
  7. }
  8. return true;
  9. }
Copy code

Note, the return of the GetImageSize() function Value is an array.

For example:

  1. $arr = getimagesize("1.jpg");
  2. /*
  3. * Here $arr is an array type
  4. * $arr[0] is the width of the image
  5. * $arr[1] is the image The height
  6. * $arr[2] is the format of the image, including jpg, gif and png, etc.
  7. * $arr[3] is the width and height of the image, the content is width="xxx" height="yyy" */
Copy code

Example 3, getimagesize function usage.

  1. $size = getimagesize($filename);
  2. $fp=fopen($filename, "rb");
  3. if ($size && $fp) { // bbs.it- home.org
  4. header("Content-type: {$size['mime']}");
  5. fpassthru($fp);
  6. exit;
  7. } else {
  8. // error
  9. }
  10. ?>
Copy the code

Example 4, getimagesize function usage (example from php manual).

  1. $size = getimagesize("testimg.jpg", &$info);
  2. if (isset($info["APP13"])) {
  3. $iptc = iptcparse($info ["APP13"]);
  4. var_dump($iptc);
  5. }
  6. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn