Class and method processing


I’m working on a class file where I like each method called and executed within the class.
In the event a method or methods run into a problem it should update the error array with the
appropriate err msgs.

the last method would verify whether error array is empty or not
if empty process the upload if not display the content of the error array.

This posting is more or less how to run all 4 methods within the class or have the last method
process the 3 methods .

$upload = new Testing(var)
$upload->processimage() - should either bring back the err message or complete the upload process pending it meets all
of the critters set by the other methods.

Markup code/class

Class Testing

public errCheck = array();

public function recordCount($_FILES[‘data’])
{ if(!count($_FILES[‘data’][‘name’] ) <= $file_Count)
{ $this->errCheck = ‘The system only allows your to upload 3 images/files’; }

public function checkimageFormat($_FILES[‘data’])
{ if (!jpg, png, gif)
{ Add message to errcheck = “incorrect format”; }

public function checkimageSize($_FILES[‘data’])
{ if (!jpg, png, gif)
{ Add message to errcheck = “incorrect size”; }

public function processimage()
{ -run the above methods
-check errCheck array to determine if the methods appended any err msgs.

 	if empty upload files.
if not empty send error message back



If the only variable is $_FILES[‘data’] it needs not be passed to the class or to its functions because it is global.

I prefer to have a second boolean error variable

public $error = FALSE;

it’s easier to test than to see what’s inside an array.

To call the functions inside the class use

// -run the above methods

// -check errCheck array to determine if the methods appended any err msgs.
if ($this->error) {
   return $this->errCheck;
} else {
   return FALSE;

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:

$file_types = array("jpg", "png", "gif");
$count = 3;

$t = new Testing($count, $file_types);
if( $t->process() ){  // ie process() return boolean
// all went ok


// something went wrong


This allows you to then, elsewhere, or at a later stage to do:

$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:

public function processimage(){


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?