/** * Vaidate the file MIME type. * * @param string $file * @return bool */ public function isValid($file) { $this->_file = $file; // Detect the definitive MIME type. $detect = new Omeka_File_MimeType_Detect($this->_file); $this->_mimeType = $detect->detect(); // Set the relevant MIME type whitelist. if ($this->_customWhitelist) { $whitelist = $this->_customWhitelist; } else { $whitelist = self::DEFAULT_WHITELIST; } // Validate the MIME type against the whitelist. if (in_array($this->_mimeType, explode(',', $whitelist))) { // Valid MIME type. Set the MIME type to the ingest class so that it // can assign it to the File record. Doing this avoids more than one // call to the MIME type detection class. Omeka_File_Ingest_AbstractIngest::$mimeType = $this->_mimeType; return true; } else { // Invalid MIME type. Zend_Debug::dump(explode(',', $whitelist)); $this->_error(self::INVALID_TYPE); return false; } }
function _dimensions_from_exif($image, $size = 'original') { try { $fn = _get_full_path($image, $size); $d = new Omeka_File_MimeType_Detect($fn); if (array_search($d->detect(), array('image/tiff', 'image/jpeg'))) { $exif_md = exif_read_data($fn, 'COMPUTED'); return array('width' => $exif_md['COMPUTED']['Width'], 'height' => $exif_md['COMPUTED']['Height']); } else { return false; } } catch (Exception $e) { $message = $e->getMessage(); _log("Getting dimensions using exif_read_data failed: {$message}"); return false; } }
/** * Insert a File record corresponding to an ingested file and its metadata. * * @param string $newFilePath Path to the file within Omeka. * @param string $oldFilename The original filename for the file. This will * usually be displayed to the end user. * @param array $elementMetadata See ActsAsElementText::addElementTextsByArray() * for more information about the format of this array. * @uses ActsAsElementText::addElementTextsByArray() * @return File */ private function _createFile($newFilePath, $oldFilename, $elementMetadata = array()) { // Normally, the MIME type validator sets the type to this class's // static $mimeType property during validation. If that validator has // been disabled (from the admin settings menu, for example), set the // MIME type here. if (self::$mimeType) { $mimeType = self::$mimeType; // Make sure types don't leak between files. self::$mimeType = null; } else { $detect = new Omeka_File_MimeType_Detect($newFilePath); $mimeType = $detect->detect(); } $file = new File(); try { $file->original_filename = $oldFilename; $file->mime_type = $mimeType; $file->setDefaults($newFilePath); if ($elementMetadata) { $file->addElementTextsByArray($elementMetadata); } fire_plugin_hook('after_ingest_file', array('file' => $file, 'item' => $this->_item)); $this->_item->addFile($file); } catch (Exception $e) { if (!$file->exists()) { $file->unlinkFile(); } throw $e; } return $file; }