upload php class

Upload PHP Class




Upload PHP class is developed to cut down the lengthy process of file upload in a simple manner. Upload php class is written with objective of `simple to use` in mind. Upload php class is written in php and its free



what Upload php class is

basically Upload PhP is a class which contain file uploading and error handling code and wrapped them together

why to use

Upload php class is created with the primary goal of being simple to use. Upload php cut the lengthy file uploading code to 1 line

index.php

Download the Upload.php from the links and include that file to the index.php then wait for the form to get submited then create a array of allowed extension.
call the Upload(); this method will take four parameters
1. upload file super global $_FILES[‘files’];
2. Directory in which the fill will be uploaded
3. Max allowed file upload size in bytes
4. allowed extension array
[php]
GetResult();
print “

";
		print_r($result);
		print "

“;
}
?>



[/php]

Upload.php class

[php]
_upload = $upload;
$this->_dir = $dir;
$this->_size = $size;
$this->_allowed = $allowed;

// call the upload method and upload the file braaaaaaaa
$this->Upload();
}

// METHOD TO UPLOAD FILE
private function Upload(){
// check weather paramters are empty
if (!empty($this->_upload) && (!empty($this->_dir)) && (!empty($this->_size)) && (!empty($this->_allowed))) {
// check $_upload & $_allowed is an array
if ((is_array($this->_upload)) && (is_array($this->_allowed))) {
// get the extension of the uploaded file
$explode = explode(“.”, strtolower($this->_upload[‘name’]));
$key = count($explode) – 1;
$extension = $explode[$key];
// check extension is allowed
if (in_array($extension, $this->_allowed)) {
// check size
if ($this->_upload[‘size’] < $this->_size) {
// upload the file
$filename = $this->_upload[‘name’];
$tmpname = $this->_upload[‘tmp_name’];
if (move_uploaded_file($tmpname, $this->_dir.$filename)) {
$this->_result[‘type’] = “success”;
$this->_result[‘message’] = “File Has been uploaded”;
$this->_result[‘path’] = $this->_dir.$filename;
}else{
$this->_result[‘type’] = “error”;
$this->_result[‘message’] = “Error in uploading file”;
$this->_result[‘path’] = false;
}
}else{
$this->_result[‘type’] = “error”;
$this->_result[‘message’] = “Fill should be less then {$this->_size} BYTES”;
$this->_result[‘path’] = false;
}
}else{
$this->_result[‘type’] = “error”;
$this->_result[‘message’] = “Fill Type not allowed”;
$this->_result[‘path’] = false;
}
}else{
$this->_result[‘type’] = “error”;
$this->_result[‘message’] = “Parameters 1st and 4th should be an array”;
$this->_result[‘path’] = false;
}
}else{
$this->_result[‘type’] = “error”;
$this->_result[‘message’] = “Parameters can not be empty”;
$this->_result[‘path’] = false;
}
}

// METHOD TO RETURN RESULT
public function GetResult(){
return $this->_result;
}
}

?>
[/php]

3 thoughts on “Upload PHP Class”

Leave a Reply

Your email address will not be published. Required fields are marked *