if (!empty($this->id)) {
$this->fileRecord = new File();
$this->fileRecord->id = $this->id;
- if (!$this->find(true)) {
+ if (!$this->fileRecord->find(true)) {
// If we have set an ID, we need that ID to exist!
throw new NoResultException($this->fileRecord);
}
if (empty($file->filename)) {
throw new UnsupportedMediaException(_('File without filename could not get a thumbnail source.'));
}
+
+ // First some mimetype specific exceptions
+ switch ($file->mimetype) {
+ case 'image/svg+xml':
+ throw new UseFileAsThumbnailException($file->id);
+ }
+
+ // And we'll only consider it an image if it has such a media type
switch ($media) {
case 'image':
$imgPath = $file->getPath();
case UPLOAD_ERR_NO_FILE:
// No file; probably just a non-AJAX submission.
+ throw new ClientException(_('No file uploaded.'));
+
default:
common_log(LOG_ERR, __METHOD__ . ": Unknown upload error " . $_FILES[$param]['error']);
// TRANS: Exception thrown when uploading an image fails for an unknown reason.
return new ImageFile(null, $_FILES[$param]['tmp_name']);
}
- /**
- * Compat interface for old code generating avatar thumbnails...
- * Saves the scaled file directly into the avatar area.
- *
- * @param int $size target width & height -- must be square
- * @param int $x (default 0) upper-left corner to crop from
- * @param int $y (default 0) upper-left corner to crop from
- * @param int $w (default full) width of image area to crop
- * @param int $h (default full) height of image area to crop
- * @return string filename
- */
- function resize($size, $x = 0, $y = 0, $w = null, $h = null)
- {
- $targetType = $this->preferredType();
- $outname = Avatar::filename($this->id,
- image_type_to_extension($targetType),
- $size,
- common_timestamp());
- $outpath = Avatar::path($outname);
- $this->resizeTo($outpath, array('width'=>$size, 'height'=>$size,
- 'x'=>$x, 'y'=>$y,
- 'w'=>$w, 'h'=>$h));
- return $outname;
- }
-
/**
* Copy the image file to the given destination.
*