⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

image crud need to add validation for fixed size image upload e.g. 600 x 800 only



sr@123

sr@123
  • profile picture
  • Member

Posted 28 May 2015 - 09:51 AM

Hello,

 

i am trying to add fixed image validation in image crud class but not succeded in it. tryed below code but not worked. image not uploaded but  database entry done. any help appreciated.

 

class ImageUploadHandler
{

========

private function has_error($uploaded_file, $file, $error) {

 

if ($uploaded_file && is_uploaded_file($uploaded_file)) {
            $file_size = filesize($uploaded_file);

list($width, $height, $type, $attr) = getimagesize($uploaded_file);

if($width != 600 || $height != 800){

return 'maxFileSize';

}

        } else {
            $file_size = $_SERVER['CONTENT_LENGTH'];
        }

 

}


jacobaugustine

jacobaugustine
  • profile picture
  • Member

Posted 07 October 2015 - 08:30 AM

Change this one

if($width != 600 || $height != 800){

return 'maxFileSize';

}
to

if($width > 600 || $height > 800){

return 'maxFileSize';

}


Martin Lobato

Martin Lobato
  • profile picture
  • Member

Posted 25 November 2016 - 19:28 PM

I need to hardocde the image name, the name must be the SKU or produc name that I 've already got from DDBB. The only thing the image crud must do is to add at the end of the file name (and ddbb) the uniqid to avoid duplicates names. 

 

I already add setters, getters and protected variable $hardcode_file_name, but reading the library got a lot of problems due to my lack of expertice, could schedule this tool for the next version?

 

Or maybe someone can get me the correct code? 

 

Thanks to all !