I'd try and make that class a bit more flexible.
What happens if you want to reuse it to check say, 4 files max, and only jpgs?
Think on designing something which handles this kind of call instead:
PHP Code:
$file_types = array("jpg", "png", "gif");
$count = 3;
$t = new Testing($count, $file_types);
if( $t->process() ){ // ie process() return boolean
// all went ok
}else{
// something went wrong
var_dump($t->getErrors());
}
This allows you to then, elsewhere, or at a later stage to do:
PHP Code:
$file_types = "jpg";
$count = 4;
$t = new Testing($count, $file_types);
... etc
I am not sure but I think your Q is asking how do I call those methods from inside the class, so returning to your code:
PHP Code:
public function processimage(){
$this->checkimageFormat();
$this->checkimageSize();
}
In any case a single class which handles uploading, moving the file, checking the size and the file type is going to get pretty big pretty fast. The trick is to remove as many variables from inside it so that you can inject them instead -- that way you have a chance of re-using it in a variety of places.
eg what if you wanted to upload a pdf file?
Bookmarks