Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Piotr  >  Easy Upload Class  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of use
Class: Easy Upload Class
Validate and process files uploaded via forms
Author: By
Last change:
Date: 2012-01-22 23:19
Size: 1,268 bytes
 

Contents

Class file image Download
if($_FILES['server_banner']['error'] != 4) {
    
    /*

        Upload(

            - variable name (<input type="file" name="THIS VALUE" />
            - upload target
            - image dimensions (optional)
            - IMAGE_EQUAL, IMAGE_MAX (optional)
                IMAGE_EQUAL:
                - image must have defined dimensions
                IMAGE_MAX:
                - you defines max acceptable image dimensions
        )

    */


    $banner = new Upload('server_banner', ROOT.'Upload/banners/', array('468', '60'), IMAGE_EQUAL);

    // DEFINE ACCEPTABLE FILESIZE

    $banner->MaxSize(204800); // 200 kb

    // DEFINE ACCEPTABLE FILE FORMAT
    // If you'll not trigger this method, upload'll accept files of any types

    $banner->AllowFormat('image/jpeg', 'image/gif', 'image/png');
                        
    if(!$banner->Upload()) {
                                                
        switch($banner->GetError()) {
                                
            case ERROR_BAD_DIMENSIONS:
                echo 'Bad image dimensions. Acceptable: 468x60px';
            break;
                                    
            case ERROR_FILE_TOO_BIG:
                echo 'File size exceeds 200kb. Size of an uploaded file is: '.$banner->GetFileSize();
            break;
                                    
            case ERROR_BAD_FORMAT:
                echo 'Bad file format. Acceptable: jpg, gif, png';
            break;
                                
        }
                        
    }

    else echo 'File has been uploaded to '.$banner->GetUploadedName();
                                                
}