PHP Classes

File: upload.php

Recommend this page to a friend!
  Classes of Taiwo Peace   Secure Upload   upload.php   Download  
File: upload.php
Role: Class source
Content type: text/plain
Description: Main Class
Class: Secure Upload
Process uploaded files of multiple types
Author: By
Last change: some minor bug fixes
Date: 9 years ago
Size: 2,304 bytes
 

Contents

Class file image Download
<?php

/**
@authour olaoluwa olorunda

 This program is open-source and part or all of it can be modified to suit your specific needs ,
 if you have any modification or suggestion to make this class better, contact me
 @email olorundaolaoluwa@gmail.com



**/


class upload{
public
$filetype , $inputname , $uploadpath , $allowedsize , $imagename ,$width , $height, $error;



function
upload(){

if(isset(
$_FILES[$this->inputname]["name"])){
//allowed extension condition
if($this->filetype=='image'){
$allowedExts = array("gif", "jpeg", "jpg","JPG", "png");
}
else if(
$this->filetype=='audio'){
$allowedExts = array("mp3", "wav", "mp4","m4a", "3gp");
}
else if(
$this->filetype=='document'){
$allowedExts = array("pdf", "doc", "docx","txt", "rtf","xls");

}
else if(
$this->filetype=='any'){
$allowedExts = array("pdf", "doc", "docx","txt", "rtf","xls","mp3", "wav", "mp4","m4a", "3gp","gif", "jpeg", "jpg","JPG", "png");

}


$temp = explode(".", $_FILES[$this->inputname]["name"]);

$extension = end($temp);

$size=$this->allowedsize*1024;


if(
$this->filetype=='image'){

$imagesize=getimagesize($_FILES[$this->inputname]["tmp_name"]) ;

}
else{

$imagesize=array(1000,1000);
}
if(!isset(
$this->width)&&!isset($this->height)){
$this->width=1000000;
$this->height=100000;

}


if ((
$_FILES[$this->inputname]["size"] < $size) &&$imagesize[0]<=$this->width &&$imagesize[1]<=$this->height&& in_array($extension, $allowedExts) ) {

 if (
$_FILES[$this->inputname]["error"] > 0 ) {
         
$this->error='upload error because'.$_FILES[$this->inputname]["error"];
    return
false;
  }
 
  else {
 
//move file from temp directory to real directory
  
move_uploaded_file($_FILES[$this->inputname]["tmp_name"], $this->uploadpath . $_FILES[$this->inputname]["name"]);
   
$this->imgname=$_FILES[$this->inputname]["name"];
     
            return
true;
      }
       
        }
       
        else{
       
        if(
$imagesize[0]>$this->width &&$imagesize[1]>$this->height){
        
$this->error='Upload error becauae file dimension is not '.$this->width.' X '.$this->height;
        }
        else{
                 
$this->error='File Extension Not Supportted';
        }
        }
        }
       
      else {
     
$this->error=' error input type name not specified';
      return
false;
      }
      }
      }