PHP Classes

File: uploadFile.php

Recommend this page to a friend!
  Classes of catalin   PHP Upload Picture   uploadFile.php   Download  
File: uploadFile.php
Role: Example script
Content type: text/plain
Description: Example file: how to use
Class: PHP Upload Picture
Validate and resize an uploaded image file
Author: By
Last change: Update of uploadFile.php
Date: 3 months ago
Size: 1,282 bytes
 

Contents

Class file image Download
<?php

include "UploadPicture.php";

//save just image without any other parameters
//this usage will save file in current directory at given size and without compression
$upload = new UploadPicture();
try {
   
$upload->savePicture($_FILES['file']);
} catch (\
Exception $exc) {
   
//do what you want in case of error
}

//save file in desired directory (for example in a directory "pictures" on a superior level
$upload1 = new UploadPicture();
$upload1->setSavePath(rtrim(__DIR__, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'pictures' . DIRECTORY_SEPARATOR);
try {
   
$upload1->savePicture($_FILES['file']);
} catch (\
Exception $exc) {
   
//do what you want in case of error
}

//save file at desired size
$upload2 = new UploadPicture();
$upload2->setDesiredSize(300, 300);
try {
   
$upload2->savePicture($_FILES['file'], null, true);
} catch (\
Exception $exc) {
   
//do what you want in case of error
}

//save file with desired name, with desired size and at compression of 90
//compression of file offer a good usage of disk
$upload3 = new UploadPicture();
$upload3->setDesiredSize(500, 300);
try {
   
$upload3->savePicture($_FILES['file'], 'MyPicture.jpg', true, 90);
} catch (\
Exception $exc) {
    echo
$exc->getMessage();
}