Search code examples
filecodeigniterclassuploading

Fixed size image upload using codeigniter, howto?


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!


Solution

  • You can use GDI library tools to find out the image height and width, aswell as other information.

    for example:

    $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