use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\event\EventHandler;
use wcf\system\exception\PermissionDeniedException;
+use wcf\system\exception\SystemException;
use wcf\system\exception\UserInputException;
use wcf\system\image\ImageHandler;
use wcf\system\request\LinkHandler;
// move uploaded file
if (@move_uploaded_file($file->getLocation(), $attachment->getLocation())) {
- if ($attachment->isImage) {
- $thumbnails[] = $attachment;
-
- // rotate image based on the exif data
- $neededMemory = $attachment->width * $attachment->height * ($attachment->fileType == 'image/png' ? 4 : 3) * 2.1;
- if (FileUtil::getMemoryLimit() == -1 || FileUtil::getMemoryLimit() > (memory_get_usage() + $neededMemory)) {
- $exifData = ExifUtil::getExifData($attachment->getLocation());
- if (!empty($exifData)) {
- $orientation = ExifUtil::getOrientation($exifData);
- if ($orientation != ExifUtil::ORIENTATION_ORIGINAL) {
- $adapter = ImageHandler::getInstance()->getAdapter();
- $adapter->loadFile($attachment->getLocation());
-
- $newImage = null;
- switch ($orientation) {
- case ExifUtil::ORIENTATION_180_ROTATE:
- $newImage = $adapter->rotate(180);
- break;
+ try {
+ if ($attachment->isImage) {
+ // rotate image based on the exif data
+ $neededMemory = $attachment->width * $attachment->height * ($attachment->fileType == 'image/png' ? 4 : 3) * 2.1;
+ if (FileUtil::getMemoryLimit() == -1 || FileUtil::getMemoryLimit() > (memory_get_usage() + $neededMemory)) {
+ $exifData = ExifUtil::getExifData($attachment->getLocation());
+ if (!empty($exifData)) {
+ $orientation = ExifUtil::getOrientation($exifData);
+ if ($orientation != ExifUtil::ORIENTATION_ORIGINAL) {
+ $adapter = ImageHandler::getInstance()->getAdapter();
+ $adapter->loadFile($attachment->getLocation());
- case ExifUtil::ORIENTATION_90_ROTATE:
- $newImage = $adapter->rotate(90);
- break;
+ $newImage = null;
+ switch ($orientation) {
+ case ExifUtil::ORIENTATION_180_ROTATE:
+ $newImage = $adapter->rotate(180);
+ break;
+
+ case ExifUtil::ORIENTATION_90_ROTATE:
+ $newImage = $adapter->rotate(90);
+ break;
+
+ case ExifUtil::ORIENTATION_270_ROTATE:
+ $newImage = $adapter->rotate(270);
+ break;
+
+ case ExifUtil::ORIENTATION_HORIZONTAL_FLIP:
+ case ExifUtil::ORIENTATION_VERTICAL_FLIP:
+ case ExifUtil::ORIENTATION_VERTICAL_FLIP_270_ROTATE:
+ case ExifUtil::ORIENTATION_HORIZONTAL_FLIP_270_ROTATE:
+ // unsupported
+ break;
+ }
- case ExifUtil::ORIENTATION_270_ROTATE:
- $newImage = $adapter->rotate(270);
- break;
+ if ($newImage !== null) {
+ $adapter->load($newImage, $adapter->getType());
+ }
- case ExifUtil::ORIENTATION_HORIZONTAL_FLIP:
- case ExifUtil::ORIENTATION_VERTICAL_FLIP:
- case ExifUtil::ORIENTATION_VERTICAL_FLIP_270_ROTATE:
- case ExifUtil::ORIENTATION_HORIZONTAL_FLIP_270_ROTATE:
- // unsupported
- break;
- }
-
- if ($newImage !== null) {
- $adapter->load($newImage, $adapter->getType());
- }
-
- $adapter->writeImage($attachment->getLocation());
-
- if ($newImage !== null) {
- // update width, height and filesize of the attachment
- if ($orientation == ExifUtil::ORIENTATION_90_ROTATE || $orientation == ExifUtil::ORIENTATION_270_ROTATE) {
- $attachmentEditor = new AttachmentEditor($attachment);
- $attachmentEditor->update(array(
- 'height' => $attachment->width,
- 'width' => $attachment->height,
- 'filesize' => filesize($attachment->getLocation())
- ));
+ $adapter->writeImage($attachment->getLocation());
+
+ if ($newImage !== null) {
+ // update width, height and filesize of the attachment
+ if ($orientation == ExifUtil::ORIENTATION_90_ROTATE || $orientation == ExifUtil::ORIENTATION_270_ROTATE) {
+ $attachmentEditor = new AttachmentEditor($attachment);
+ $attachmentEditor->update(array(
+ 'height' => $attachment->width,
+ 'width' => $attachment->height,
+ 'filesize' => filesize($attachment->getLocation())
+ ));
+ }
}
}
}
}
+
+ $thumbnails[] = $attachment;
}
+ else {
+ // check whether we can create thumbnails for this file
+ $this->eventAttachment = $attachment;
+ $this->eventData = array('hasThumbnail' => false);
+ EventHandler::getInstance()->fireAction($this, 'checkThumbnail');
+ if ($this->eventData['hasThumbnail']) $thumbnails[] = $attachment;
+ }
+ $attachments[$file->getInternalFileID()] = $attachment;
}
- else {
- // check whether we can create thumbnails for this file
- $this->eventAttachment = $attachment;
- $this->eventData = array('hasThumbnail' => false);
- EventHandler::getInstance()->fireAction($this, 'checkThumbnail');
- if ($this->eventData['hasThumbnail']) $thumbnails[] = $attachment;
+ catch (SystemException $e) {
+ // processing failed; delete attachment
+ $editor = new AttachmentEditor($attachment);
+ $editor->delete();
+
+ // log error
+ $e->getExceptionID();
}
- $attachments[$file->getInternalFileID()] = $attachment;
}
else {
// moving failed; delete attachment