upload_images = array(); } function add_upload_images($key, $image_name) { // key would usually be passed in as a form field $this->upload_images[$key] = $image_name; } function is_uploaded($file_field, $fieldIndex='') { if($fieldIndex == '') { if(isset($_FILES[$file_field]) && is_uploaded_file($_FILES[$file_field]['tmp_name'])) { return(TRUE); } else // IMAGE FILE NOT UPLOADED - PROBABLY USER ERROR { $this->upload_error = 'No file to upload'; return(FALSE); } } else { if(isset($_FILES[$file_field]['name'][$fieldIndex]) && is_uploaded_file($_FILES[$file_field]['tmp_name'][$fieldIndex])) { return(TRUE); } else // IMAGE FILE NOT UPLOADED - PROBABLY USER ERROR { $this->upload_error = 'No file to upload'; return(FALSE); } } } function check_image_type($image_info, $image_types) { return(in_array($image_info[2], $image_types)); } function file_exists($physfile) { echo 'fix me: file_exists';exit(); return (is_file($physfile)); } function create_image_name($image_info) { // RENAME FILES TO SOMETHING VERY RANDOM (AND VALID) $random = rand(0, 999999999); $ext = $this->image_ext($image_info[2]); $filename = $random.".".$ext; // recursive check for file existence if(Database::ado_get_record_count("SELECT id FROM ".Config::$db_tables['inventory_item_images']." WHERE imagefile='$filename'", "Upload::create_image_name") > 0) { $this->create_image_name($image_info, $Database); } else { return($filename); } } function process_upload($file_field, $images, $resize=TRUE, $fieldIndex='') { // eventually use an Image object instead of $images $uploadedFile = ($fieldIndex == '') ? $_FILES[$file_field]['tmp_name'] : $_FILES[$file_field]['tmp_name'][$fieldIndex]; $image_sz = getimagesize($uploadedFile); $valid_image_types = array(1,2); if(!$this->check_image_type($image_sz, $valid_image_types)) { $this->upload_error = 'Image must be a jpg or gif'; // not generalized return(FALSE); } $upload_image = $this->create_image_name($image_sz); foreach($images as $image_size=>$image_info) { if(!isset($image_info['skip']) || !$image_info['skip']) // way to bypass one of the image types in the array { $dest = Config::$path_to_www.$image_info['web_location'].$upload_image; if(Config::$location == 'local') { $dest = str_replace('/', '\\', $dest); } $width = ($resize) ? $image_info['width'] : $image_sz[0]; $height = ($resize) ? $image_info['height'] : $image_sz[1]; $this->createthumb($uploadedFile, $dest, $width, $height, $image_info['quality']); exec("chmod 777 ".$dest); } } return($upload_image); } function image_ext($imagetype) { switch($imagetype) { case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; } return($ext); } function createthumb($src,$dest,$maxWidth,$maxHeight,$quality) { //echo $src. ' ' . $dest. ' ' . $maxWidth. ' ' . $maxHeight. ' ' . $quality.'
'; if (file_exists($src) && isset($dest)) { // path info $destInfo = pathinfo($dest); // image src size $srcSize = getimagesize($src); // image dest size $destSize[0] = width, $destSize[1] = height $srcRatio = $srcSize[0]/$srcSize[1]; // width/height ratio $destRatio = $maxWidth/$maxHeight; if ($destRatio > $srcRatio) { $destSize[1] = $maxHeight; $destSize[0] = $maxHeight*$srcRatio; } else { $destSize[0] = $maxWidth; $destSize[1] = $maxWidth/$srcRatio; } // path rectification //if ($destInfo['extension'] == "gif") { //$dest = substr_replace($dest, 'jpg', -3); //} // true color image, with anti-aliasing $destImage = imagecreatetruecolor($destSize[0],$destSize[1]); // src image switch ($srcSize[2]) { case 1: //GIF $srcImage = imagecreatefromgif($src); break; case 2: //JPEG $srcImage = imagecreatefromjpeg($src); break; case 3: //PNG $srcImage = imagecreatefrompng($src); break; default: return false; break; } // resampling imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,$destSize[0],$destSize[1],$srcSize[0],$srcSize[1]); // generating image switch ($srcSize[2]) { case 1: imagegif($destImage,$dest,$quality); break; case 2: imagejpeg($destImage,$dest,$quality); break; case 3: imagepng($destImage,$dest); break; } return true; } else { return false; } } // function createthumb } ?>