00001 <?php
00011 class ppFile extends Plugin
00012 {
00013 var $mimetypes = array('image/png', 'image/pjpeg', 'image/jpeg', 'image/jpg', 'image/gif');
00014 var $jpeg_quality = 100;
00015
00016 function ppFile() {
00017 $this->Plugin();
00018
00019 if(!defined('JPEG_QUALITY')) {
00020 define('JPEG_QUALITY', $this->jpeg_quality);
00021 }
00022 }
00023
00027 function is_uploaded($key)
00028 {
00029 return !empty($_FILES[$key]['name']);
00030 }
00031
00035 function move($key, $destpath)
00036 {
00037 return move_uploaded_file($_FILES[$key]['tmp_name'], $destpath);
00038 }
00039
00043 function process_image($key, $destpath, $max_width=false, $max_height=false)
00044 {
00045 $this->depend('image');
00046
00047 if(empty($_FILES[$key]['name'])) return true;
00048 if($_FILES[$key]['error'] > 0) {
00049 return __('An error occurred during file upload. Please try again.');
00050 }
00051
00052
00053 $found = false;
00054 foreach($this->mimetypes as $mime) {
00055 if($_FILES[$key]['type'] == $mime) $found = true;
00056 }
00057 if(!$found) {
00058 return __('This file does not look like a valid image. Please upload a GIF, PNG, or JPEG.');
00059 }
00060
00061 return $this->depends->image->resize($_FILES[$key]['type'], $_FILES[$key]['tmp_name'], $destpath, $max_width, $max_height);
00062 }
00063 }
00064
00065 ?>