Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- class Upload {
- private $filesize,$upload,$path;
- function __construct($filesize,$upload,$path) {
- $this->filesize = $filesize;
- $this->upload = $upload;
- $this->path = $path;
- $this->source = $source;
- }
- function calcImage($image) {
- }
- function uploadImage($maxHeight = '',$maxWidth = '') {
- if($this->upload['size'] < $this->filesize && !$this->upload['error']) {
- $this->path = $this->path . substr(hash('sha512', uniqid(rand(), true)), 0, 6) . strtolower(preg_replace('/[^0-9A-Za-z.]/i', '', basename($this->upload['name'])));
- if(@move_uploaded_file($this->upload['tmp_name'], $this->path)) {
- if($maxHeight && $maxWidth) {
- switch($this->upload['type']) {
- case 'image/png':
- $this->source = imagecreatefrompng($this->path);
- break;
- case 'image/jpeg':
- $this->source = imagecreatefromjpeg($this->path);
- break;
- case 'image/gif':
- $this->source = imagecreatefromgif($this->path);
- break;
- }
- list($width, $height) = getimagesize($this->path);
- $xRatio = $maxWidth / $width;
- $yRatio = $maxHeight / $height;
- if (($width <= $maxWidth) && ($height <= $maxHeight)) {
- $newWidth = $width;
- $newHeight = $height;
- }
- elseif (($xRatio * $height) < $maxHeight) {
- $newHeight = ceil($xRatio * $height);
- $newWidth = $maxWidth;
- }
- else {
- $newWidth = ceil($yRatio * $width);
- $newHeight = $maxHeight;
- }
- $tmp = imagecreatetruecolor($newWidth, $newHeight);
- imagecopyresampled($tmp, $this->source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
- if(@unlink($this->path)) {
- imagejpeg($tmp, $this->path, 100);
- imagedestroy($this->source);
- imagedestroy($tmp);
- }
- }
- return $this->path;
- }
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment