[geeklog-cvs] geeklog-1.3/system/classes upload.class.php,1.31,1.32
dhaun at iowaoutdoors.org
dhaun at iowaoutdoors.org
Sat Jul 10 13:32:05 EDT 2004
Update of /var/cvs/geeklog-1.3/system/classes
In directory www:/tmp/cvs-serv16732/system/classes
Modified Files:
upload.class.php
Log Message:
Fixed image resize problems when the image height > max. height, but the width < max. width (bug #242). Also fixed keeping the unscaled image when using GDlib (bug #197).
Index: upload.class.php
===================================================================
RCS file: /var/cvs/geeklog-1.3/system/classes/upload.class.php,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** upload.class.php 12 Jan 2004 20:07:41 -0000 1.31
--- upload.class.php 10 Jul 2004 17:32:02 -0000 1.32
***************
*** 9,15 ****
// | |
// +---------------------------------------------------------------------------+
! // | Copyright (C) 2002 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony at tonybibbs.com |
// +---------------------------------------------------------------------------+
// | |
--- 9,16 ----
// | |
// +---------------------------------------------------------------------------+
! // | Copyright (C) 2002-2004 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony at tonybibbs.com |
+ // | Dirk Haun - dirk at haun-online.de |
// +---------------------------------------------------------------------------+
// | |
***************
*** 169,173 ****
$this->_setAvailableMimeTypes();
}
!
// PRIVATE METHODS
--- 170,174 ----
$this->_setAvailableMimeTypes();
}
!
// PRIVATE METHODS
***************
*** 188,192 ****
}
}
!
/**
* Adds an error that was encountered
--- 189,193 ----
}
}
!
/**
* Adds an error that was encountered
***************
*** 222,226 ****
}
}
!
/**
* Logs an item to the log file
--- 223,227 ----
}
}
!
/**
* Logs an item to the log file
***************
*** 245,249 ****
return true;
}
!
/**
* Defines superset of available Mime types.
--- 246,250 ----
return true;
}
!
/**
* Defines superset of available Mime types.
***************
*** 281,285 ****
}
}
!
/**
* Checks if current file is an image
--- 282,286 ----
}
}
!
/**
* Checks if current file is an image
***************
*** 305,312 ****
$this->_addDebugMsg($msg);
}
!
return $isImage;
}
!
/**
* Verifies the file size meets specified size limitations
--- 306,313 ----
$this->_addDebugMsg($msg);
}
!
return $isImage;
}
!
/**
* Verifies the file size meets specified size limitations
***************
*** 341,354 ****
return true;
}
!
$imageInfo = $this->_getImageDimensions($this->_currentFile['tmp_name']);
!
$sizeOK = true;
!
if ($this->_debug) {
$this->_addDebugMsg('Max allowed width = ' . $this->_maxImageWidth . ', Image width = ' . $imageInfo['width']);
$this->_addDebugMsg('Max allowed height = ' . $this->_maxImageHeight . ', Image height = ' . $imageInfo['height']);
}
!
// If user set _autoResize then ignore these settings and try to resize on upload
if (($doResizeCheck AND !($this->_autoResize)) OR (!($doResizeCheck))) {
--- 342,355 ----
return true;
}
!
$imageInfo = $this->_getImageDimensions($this->_currentFile['tmp_name']);
!
$sizeOK = true;
!
if ($this->_debug) {
$this->_addDebugMsg('Max allowed width = ' . $this->_maxImageWidth . ', Image width = ' . $imageInfo['width']);
$this->_addDebugMsg('Max allowed height = ' . $this->_maxImageHeight . ', Image height = ' . $imageInfo['height']);
}
!
// If user set _autoResize then ignore these settings and try to resize on upload
if (($doResizeCheck AND !($this->_autoResize)) OR (!($doResizeCheck))) {
***************
*** 375,379 ****
return $sizeOK;
}
!
/**
* Gets the width and height of an image
--- 376,380 ----
return $sizeOK;
}
!
/**
* Gets the width and height of an image
***************
*** 390,394 ****
return array('width' => $dimensions[0], 'height' => $dimensions[1]);
}
!
/**
* Gets destination file name for current file
--- 391,447 ----
return array('width' => $dimensions[0], 'height' => $dimensions[1]);
}
!
! /**
! * Calculate the factor to scale images with if they're not meeting
! * the size restrictions.
! *
! * @access private
! * @param int $width width of the unscaled image
! * @param int $height height of the unscaled image
! * @return double resize factor
! *
! */
! function _calcSizefactor ($width, $height)
! {
! if (($width > $this->_maxImageWidth) ||
! ($height > $this->_maxImageHeight)) {
! if (($width > $this->_maxImageWidth) && ($width > $height)) {
! $sizefactor = (double) ($this->_maxImageWidth / $width);
! } else {
! $sizefactor = (double) ($this->_maxImageHeight / $height);
! }
! } else {
! $sizefactor = 1.0;
! }
!
! return $sizefactor;
! }
!
! /**
! * Keep the original (unscaled) image file, if configured.
! *
! * @access private
! * @param string $filename name of uploaded file
! * @return bool true: okay, false: an error occured
! *
! */
! function _keepOriginalFile ($filename)
! {
! if ($this->_keepOriginalImage) {
! $lFilename_large = substr_replace ($this->_getDestinationName (),
! '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
! $lFilename_large_complete = $this->_fileUploadDirectory . '/'
! . $lFilename_large;
! if (!copy ($filename, $lFilename_large_complete)) {
! $this->_addError ("Couldn't copy $filename to $lFilename_large_complete. You'll need to remove both files.");
! $this->printErrors ();
!
! return false;
! }
! }
!
! return true;
! }
!
/**
* Gets destination file name for current file
***************
*** 431,438 ****
$perms = '';
}
!
return $perms;
}
!
/**
* This function actually completes the upload of a file
--- 484,491 ----
$perms = '';
}
!
return $perms;
}
!
/**
* This function actually completes the upload of a file
***************
*** 464,472 ****
if (!($sizeOK)) {
// OK, resize
! if ($imageInfo['height'] > $imageInfo['width']) {
! $sizefactor = (double) ($this->_maxImageHeight / $imageInfo['height']);
! } else {
! $sizefactor = (double) ($this->_maxImageWidth / $imageInfo['width']);
! }
$newwidth = (int) ($imageInfo['width'] * $sizefactor);
$newheight = (int) ($imageInfo['height'] * $sizefactor);
--- 517,522 ----
if (!($sizeOK)) {
// OK, resize
! $sizefactor = $this->_calcSizefactor ($imageInfo['width'],
! $imageInfo['height']);
$newwidth = (int) ($imageInfo['width'] * $sizefactor);
$newheight = (int) ($imageInfo['height'] * $sizefactor);
***************
*** 479,493 ****
$this->_addDebugMsg('Attempting to resize with this command (imagemagick): ' . $cmd);
! if ($this->_keepOriginalImage) {
! $filename = $this->_fileUploadDirectory . '/'
! . $this->_getDestinationName ();
! $lFilename_large = substr_replace ($this->_getDestinationName (), '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
! $lFilename_large_complete = $this->_fileUploadDirectory
! . '/' . $lFilename_large;
! if (!copy ($filename, $lFilename_large_complete)) {
! $this->_addError ("Couldn't copy $filename to $lFilename_large_complete. You'll need to remove both files.");
! $this->printErrors ();
! exit;
! }
}
--- 529,536 ----
$this->_addDebugMsg('Attempting to resize with this command (imagemagick): ' . $cmd);
! $filename = $this->_fileUploadDirectory . '/'
! . $this->_getDestinationName ();
! if (!$this->_keepOriginalFile ($filename)) {
! exit;
}
***************
*** 518,530 ****
exec($cmd, $netpbm_output, $retval);
! if ($this->_keepOriginalImage) {
! $lFilename_large = substr_replace ($this->_getDestinationName(), '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
! $lFilename_large_complete = $this->_fileUploadDirectory
! . '/' . $lFilename_large;
! if (!copy ($filename, $lFilename_large_complete)) {
! $this->_addError ("Couldn't copy $filename to $lFilename_large_complete. You'll need to remove both files.");
! $this->printErrors ();
! exit;
! }
}
--- 561,566 ----
exec($cmd, $netpbm_output, $retval);
! if (!$this->_keepOriginalFile ($filename)) {
! exit;
}
***************
*** 590,595 ****
--- 626,640 ----
}
+ if (!$this->_keepOriginalFile ($filename)) {
+ exit;
+ }
+
if (($this->_currentFile['type'] == 'image/png') OR
($this->_currentFile['type'] == 'image/x-png')) {
+ if (!function_exists ('imagecreatefrompng')) {
+ $this->_addError ('Sorry, this version of the GD library does not support PNG images.');
+ $this->printErrors ();
+ exit;
+ }
if (!$image_source = imagecreatefrompng ($filename)) {
$this->_addError ('Could not create image from PNG: '
***************
*** 600,603 ****
--- 645,653 ----
} elseif (($this->_currentFile['type'] == 'image/jpeg') OR
($this->_currentFile['type'] == 'image/pjpeg')) {
+ if (!function_exists ('imagecreatefromjpeg')) {
+ $this->_addError ('Sorry, this version of the GD library does not support JPEG images.');
+ $this->printErrors ();
+ exit;
+ }
if (!$image_source = imagecreatefromjpeg ($filename)) {
$this->_addError ('Could not create image from JPEG: '
***************
*** 614,622 ****
// do resize
! if ($imageInfo['height'] > $imageInfo['width']) {
! $sizefactor = (double) ($this->_maxImageHeight / $imageInfo['height']);
! } else {
! $sizefactor = (double) ($this->_maxImageWidth / $imageInfo['width']);
! }
$this->_addDebugMsg ('Resizing image, factor=' . $sizefactor);
$newwidth = (int) ($imageInfo['width'] * $sizefactor);
--- 664,669 ----
// do resize
! $sizefactor = _calcSizefactor ($imageInfo['width'],
! $imageInfo['height']);
$this->_addDebugMsg ('Resizing image, factor=' . $sizefactor);
$newwidth = (int) ($imageInfo['width'] * $sizefactor);
***************
*** 667,671 ****
}
}
!
if ($returnMove AND $returnChmod) {
return true;
--- 714,718 ----
}
}
!
if ($returnMove AND $returnChmod) {
return true;
***************
*** 674,682 ****
$this->_addError('Upload of ' . $this->_currentFile['name'] . ' failed.');
}
!
if (!$returnChmod) {
$this->_addError('Chmod of ' . $this->_currentFile['name'] . ' to ' . $perms . ' failed');
}
!
return false;
}
--- 721,729 ----
$this->_addError('Upload of ' . $this->_currentFile['name'] . ' failed.');
}
!
if (!$returnChmod) {
$this->_addError('Chmod of ' . $this->_currentFile['name'] . ' to ' . $perms . ' failed');
}
!
return false;
}
***************
*** 724,728 ****
/**
! * Sets mode to autmatically resize images that are either too wide or
* too tall
*
--- 771,775 ----
/**
! * Sets mode to automatically resize images that are either too wide or
* too tall
*
***************
*** 770,774 ****
return true;
}
!
/**
* Sets the max number of files that can be uploaded per form
--- 817,821 ----
return true;
}
!
/**
* Sets the max number of files that can be uploaded per form
***************
*** 797,801 ****
return true;
}
!
/**
* Extra security option that forces all attempts to upload a file to be done
--- 844,848 ----
return true;
}
!
/**
* Extra security option that forces all attempts to upload a file to be done
***************
*** 817,826 ****
}
}
!
/**
* Allows you to specify whether or not to continue processing other files
* when an error occurs or exit immediately. Default is to exit immediately
*
! * NOTE: this only effects the actual file upload process.
*
* @param boolean $switch true or false
--- 864,873 ----
}
}
!
/**
* Allows you to specify whether or not to continue processing other files
* when an error occurs or exit immediately. Default is to exit immediately
*
! * NOTE: this only affects the actual file upload process.
*
* @param boolean $switch true or false
***************
*** 835,839 ****
}
}
!
/**
* Sets log file
--- 882,886 ----
}
}
!
/**
* Sets log file
***************
*** 854,858 ****
return true;
}
!
/**
* Enables/disables logging of errors and warnings
--- 901,905 ----
return true;
}
!
/**
* Enables/disables logging of errors and warnings
***************
*** 901,905 ****
}
}
!
/**
* This function will print any errors out. This is useful in debugging
--- 948,952 ----
}
}
!
/**
* This function will print any errors out. This is useful in debugging
***************
*** 926,930 ****
}
}
!
/**
* This function will print any warnings out. This is useful in debugging
--- 973,977 ----
}
}
!
/**
* This function will print any warnings out. This is useful in debugging
***************
*** 942,946 ****
}
}
!
/**
* This function will print any debmug messages out.
--- 989,993 ----
}
}
!
/**
* This function will print any debmug messages out.
***************
*** 958,962 ****
}
}
!
/**
* Returns if any errors have been encountered thus far
--- 1005,1009 ----
}
}
!
/**
* Returns if any errors have been encountered thus far
***************
*** 973,977 ****
}
}
!
/**
* Sets allowed mime types for this instance
--- 1020,1024 ----
}
}
!
/**
* Sets allowed mime types for this instance
***************
*** 984,988 ****
$this->_allowedMimeTypes = $mimeTypes;
}
!
/**
* Gets allowed mime types for this instance
--- 1031,1035 ----
$this->_allowedMimeTypes = $mimeTypes;
}
!
/**
* Gets allowed mime types for this instance
***************
*** 995,999 ****
return $this->_allowedMimeTypes;
}
!
/**
* Checks to see that mime type for current file is allowed for upload
--- 1042,1046 ----
return $this->_allowedMimeTypes;
}
!
/**
* Checks to see that mime type for current file is allowed for upload
***************
*** 1025,1029 ****
return false;
}
!
/**
* Sets file upload path
--- 1072,1076 ----
return false;
}
!
/**
* Sets file upload path
***************
*** 1039,1053 ****
return false;
}
!
if (!is_writable($uploadDir)) {
$this->_addError('Specified upload directory, ' . $uploadDir . ' exists but is not writable');
return false;
}
!
$this->_fileUploadDirectory = $uploadDir;
!
return true;
}
!
/**
* Returns directory to upload to
--- 1086,1100 ----
return false;
}
!
if (!is_writable($uploadDir)) {
$this->_addError('Specified upload directory, ' . $uploadDir . ' exists but is not writable');
return false;
}
!
$this->_fileUploadDirectory = $uploadDir;
!
return true;
}
!
/**
* Returns directory to upload to
***************
*** 1060,1064 ****
return $this->_fileUploadDirectory;
}
!
/**
* Sets file name(s) for files
--- 1107,1111 ----
return $this->_fileUploadDirectory;
}
!
/**
* Sets file name(s) for files
***************
*** 1101,1105 ****
}
}
!
/**
* Returns how many actual files were sent for upload. NOTE: this will
--- 1148,1152 ----
}
}
!
/**
* Returns how many actual files were sent for upload. NOTE: this will
***************
*** 1114,1120 ****
$this->_filesToUpload = $GLOBALS['HTTP_POST_FILES'];
}
!
$fcount = 0;
!
for ($i = 1; $i <= count($GLOBALS['HTTP_POST_FILES']); $i++) {
$curFile = current($this->_filesToUpload);
--- 1161,1167 ----
$this->_filesToUpload = $GLOBALS['HTTP_POST_FILES'];
}
!
$fcount = 0;
!
for ($i = 1; $i <= count($GLOBALS['HTTP_POST_FILES']); $i++) {
$curFile = current($this->_filesToUpload);
***************
*** 1127,1134 ****
}
reset($GLOBALS['HTTP_POST_FILES']);
!
return $fcount;
}
!
/**
* Uploads any posted files.
--- 1174,1181 ----
}
reset($GLOBALS['HTTP_POST_FILES']);
!
return $fcount;
}
!
/**
* Uploads any posted files.
***************
*** 1148,1157 ****
}
}
!
$this->_filesToUpload = $GLOBALS['HTTP_POST_FILES'];
$numFiles = count($this->_filesToUpload);
!
! // For security sake, check to make sure a DOS isn't happening by making sure
! // there is a limit of the number of files being uploaded
if ($numFiles > $this->_maxFileUploadsPerForm) {
$this->_addError('Max. number of files you can upload from a form is '
--- 1195,1204 ----
}
}
!
$this->_filesToUpload = $GLOBALS['HTTP_POST_FILES'];
$numFiles = count($this->_filesToUpload);
!
! // For security sake, check to make sure a DOS isn't happening by making
! // sure there is a limit of the number of files being uploaded
if ($numFiles > $this->_maxFileUploadsPerForm) {
$this->_addError('Max. number of files you can upload from a form is '
***************
*** 1164,1177 ****
$this->_addError('No Upload Directory Specified, use setPath() method');
}
!
// Verify allowed mime types exist
if (!$this->_allowedMimeTypes) {
$this->_addError('No allowed mime types specified, use setAllowedMimeTypes() method');
}
!
for ($i = 1; $i <= $numFiles; $i++) {
!
$this->_currentFile = current($GLOBALS['HTTP_POST_FILES']);
!
// Make sure file field on HTML form wasn't empty before proceeding
if (!empty($this->_currentFile['name'])) {
--- 1211,1224 ----
$this->_addError('No Upload Directory Specified, use setPath() method');
}
!
// Verify allowed mime types exist
if (!$this->_allowedMimeTypes) {
$this->_addError('No allowed mime types specified, use setAllowedMimeTypes() method');
}
!
for ($i = 1; $i <= $numFiles; $i++) {
!
$this->_currentFile = current($GLOBALS['HTTP_POST_FILES']);
!
// Make sure file field on HTML form wasn't empty before proceeding
if (!empty($this->_currentFile['name'])) {
***************
*** 1180,1184 ****
$this->_addError('File, ' . $this->_currentFile['name'] . ', is bigger than the ' . $this->_maxFileSize . ' byte limit');
}
!
// If all systems check, do the upload
if ($this->checkMimeType() AND $this->_imageSizeOK() AND !$this->areErrors()) {
--- 1227,1231 ----
$this->_addError('File, ' . $this->_currentFile['name'] . ', is bigger than the ' . $this->_maxFileSize . ' byte limit');
}
!
// If all systems check, do the upload
if ($this->checkMimeType() AND $this->_imageSizeOK() AND !$this->areErrors()) {
***************
*** 1187,1197 ****
}
}
!
$this->_currentFile = array();
!
if ($this->areErrors() AND !$this->_continueOnError) {
return false;
}
!
$this->_imageIndex++;
} else {
--- 1234,1244 ----
}
}
!
$this->_currentFile = array();
!
if ($this->areErrors() AND !$this->_continueOnError) {
return false;
}
!
$this->_imageIndex++;
} else {
***************
*** 1201,1205 ****
next($GLOBALS['HTTP_POST_FILES']);
}
!
// This function returns false if any errors were encountered
if ($this->areErrors()) {
--- 1248,1252 ----
next($GLOBALS['HTTP_POST_FILES']);
}
!
// This function returns false if any errors were encountered
if ($this->areErrors()) {
More information about the geeklog-cvs
mailing list