improved filetype error handling
This commit is contained in:
parent
86f7a06ed0
commit
5446f29141
2 changed files with 15 additions and 3 deletions
|
@ -317,6 +317,9 @@ abstract class DataHandlerExtension extends Extension
|
||||||
if (is_null($image)) {
|
if (is_null($image)) {
|
||||||
throw new UploadException("Data handler failed to create image object from data");
|
throw new UploadException("Data handler failed to create image object from data");
|
||||||
}
|
}
|
||||||
|
if (empty($image->ext)) {
|
||||||
|
throw new UploadException("Unable to determine extension for ". $event->tmpname);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
send_event(new MediaCheckPropertiesEvent($image));
|
send_event(new MediaCheckPropertiesEvent($image));
|
||||||
} catch (MediaException $e) {
|
} catch (MediaException $e) {
|
||||||
|
@ -330,6 +333,9 @@ abstract class DataHandlerExtension extends Extension
|
||||||
if (is_null($image)) {
|
if (is_null($image)) {
|
||||||
throw new UploadException("Data handler failed to create image object from data");
|
throw new UploadException("Data handler failed to create image object from data");
|
||||||
}
|
}
|
||||||
|
if (empty($image->ext)) {
|
||||||
|
throw new UploadException("Unable to determine extension for ". $event->tmpname);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
send_event(new MediaCheckPropertiesEvent($image));
|
send_event(new MediaCheckPropertiesEvent($image));
|
||||||
} catch (MediaException $e) {
|
} catch (MediaException $e) {
|
||||||
|
@ -404,9 +410,11 @@ abstract class DataHandlerExtension extends Extension
|
||||||
$image->filename = (($pos = strpos($metadata['filename'], '?')) !== false) ? substr($metadata['filename'], 0, $pos) : $metadata['filename'];
|
$image->filename = (($pos = strpos($metadata['filename'], '?')) !== false) ? substr($metadata['filename'], 0, $pos) : $metadata['filename'];
|
||||||
if ($config->get_bool("upload_use_mime")) {
|
if ($config->get_bool("upload_use_mime")) {
|
||||||
$image->ext = get_extension_for_file($filename);
|
$image->ext = get_extension_for_file($filename);
|
||||||
} else {
|
}
|
||||||
|
if (empty($image->ext)) {
|
||||||
$image->ext = (($pos = strpos($metadata['extension'], '?')) !== false) ? substr($metadata['extension'], 0, $pos) : $metadata['extension'];
|
$image->ext = (($pos = strpos($metadata['extension'], '?')) !== false) ? substr($metadata['extension'], 0, $pos) : $metadata['extension'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
||||||
$image->source = $metadata['source'];
|
$image->source = $metadata['source'];
|
||||||
|
|
||||||
|
@ -428,7 +436,7 @@ abstract class DataHandlerExtension extends Extension
|
||||||
foreach (getSubclassesOf("DataHandlerExtension") as $handler) {
|
foreach (getSubclassesOf("DataHandlerExtension") as $handler) {
|
||||||
$handler = (new $handler());
|
$handler = (new $handler());
|
||||||
|
|
||||||
foreach($handler->SUPPORTED_MIME as $mime) {
|
foreach ($handler->SUPPORTED_MIME as $mime) {
|
||||||
$arr = array_merge($arr, get_all_extension_for_mime($mime));
|
$arr = array_merge($arr, get_all_extension_for_mime($mime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ class DataUploadEvent extends Event
|
||||||
$filetype = get_extension_for_file($tmpname);
|
$filetype = get_extension_for_file($tmpname);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($filetype)) {
|
if (empty($filetype)) {
|
||||||
if (array_key_exists('extension', $metadata) && !empty($metadata['extension'])) {
|
if (array_key_exists('extension', $metadata) && !empty($metadata['extension'])) {
|
||||||
$filetype = strtolower($metadata['extension']);
|
$filetype = strtolower($metadata['extension']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,6 +56,10 @@ class DataUploadEvent extends Event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($filetype)) {
|
||||||
|
throw new UploadException("Could not determine extension for file " . $metadata["filename"]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->set_type($filetype);
|
$this->set_type($filetype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue