1

I am using the file uploading class in codeigniter and can successfully upload images. My question is how to go about making sure the user uploads an image of only a fixed size, 600px by 360px, nothing more nothing less? I have tried using the upload data array to get the image height and width and am checking against these values TRUE or FALSE. If false, I pass an error string to the view, if true, I display nothing in the view, but I am not sure it is working right. Any one can help with how to go about doing this? Thank you in advance!

4

2 回答 2

2

您可以将图像处理库与文件上传库结合使用。

使用文件上传库,您可以:

  • 确保上传的文件具有您想要的确切大小:

如果需要,您可以使用图像处理库来调整上传图像的大小,因此完整的解决方案如下所示:

$fileInfo = $this->upload->data();

if( $fileInfo['width'] == 600 && $fileInfo['height'] == 300 ) {
    // do something
} else {
    // initiialize library
    $this->image_lib->resize();
}

您可以在此处阅读有关这些库的更多信息:

http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html

http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

于 2013-04-21T15:08:57.697 回答
1

您可以使用 GDI 库工具找出图像的高度和宽度以及其他信息。

例如:

$imgInfo = getimagesize("/path/to/image.png");
if ($imgInfo[0] != 600) && $imgInfo[1] != 360){
   throw new Exception("Illegal image size");
}

http://www.php.net/manual/en/function.getimagesize.php

于 2013-04-21T15:06:53.220 回答