Login   Register  
PHP Classes
elePHPant
Icontem

File: uploadImage.Class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jonathan Alexey  >  UploadFile  >  uploadImage.Class.php  >  Download  
File: uploadImage.Class.php
Role: Application script
Content type: text/plain
Description: aplication to upload file
Class: UploadFile
Process uploaded image files
Author: By
Last change: change method the for to in_array .. =)
Date: 2010-01-22 02:46
Size: 2,375 bytes
 

Contents

Class file image Download
<?php
include("baseClass/uploadEngineClass.php");
class 
uploadImage extends uploadFile {
    
    
/*#
    #
    # Son Class
    #
    # Version: 1.0
    #
    #
    */#
    
    
var $maxWidth;
    var 
$maxHeight;
    var 
$maxSize;
    var 
$parmsType;
    var 
$nameUnique;
    var 
$extension_de;
    
    function 
uploadImage($name,$tmp_name,$size,$type,$erro="0"){
        
$this->uploadFile($name,$tmp_name,$size,$type,$erro);
        
$this->extension_de=array();
    }
    
    function 
setMaxHeight ($value) {
        
$this->maxHeight=$value;
    }
    
    function 
setMaxWidth ($value) {
        
$this->maxWidth=$value;
    }
    
    function 
setMaxSize ($value) {
        
$this->maxSize=$value;
    }
    
    function 
setDestinationImage($tmp,$dir){
        
$this->setDestinationFile($tmp,$dir);
    }
    
    function 
newNameFile ($prefix_name="Img",$more_entropy=false) {
        
$extensao=explode(".",$this->fileName);
        
$name=uniqid($prefix_name,$more_entropy);
           
$this->fileName=$name.".".$extensao[1];
    }
    
    function 
setExtension ($extension) {
        
array_push($this->extension_de,$extension);    
    }
    
    function 
getName () {
        return 
$this->fileName;
    }
    
    function 
getExtension () {
        
$file=$this->getName();
        
$setPart=explode(".",$file);
        
$extension=end($setPart);
        if(
in_array($extension,$this->extension_de)) {
            return 
true;
        }else{
            return 
false;
        }        
    }
    
    function 
moveImage(){
        if(
$this->moveFile()) {
            
$parms=getimagesize($this->fileDestinationTmp.$this->fileName);
            
$xx=$parms['0'];
            
$yy=$parms['1'];
            if(
$xx>$this->maxHeight and $yy>$this->maxWidth) {
                    
$this->fileUnlink($this->fileDestinationTmp.$this->fileName);
                    return 
false;
                }else{
                    if(
$this->fileSize>$this->maxSize) {
                        
$this->fileUnlink($this->fileDestinationTmp.$this->fileName);
                        return 
false;
                    }else{
                        if(
$this->getExtension()) {
                            if(
$this->copyFile($this->fileDestinationTmp,$this->fileDestination)) {
                                
$this->fileUnlink($this->fileDestinationTmp.$this->fileName);
                                return 
true;
                            }else{
                                
$this->fileUnlink($this->fileDestinationTmp.$this->fileName);
                                return 
false;
                            }
                        }else{
                            
$this->fileUnlink($this->fileDestinationTmp.$this->fileName);
                            return 
false;
                        }    
                    }    
                }
            }
    }
}