/** * Runs the test. */ public function test() { $path = DIR_FILES . '/mail/logo.gif'; $name = 'logo.gif'; $mimeType = 'image/gif'; $attachment = new File($path, $name, $mimeType); $this->assertEquals(file_get_contents($path), $attachment->getContent()); $this->assertEquals($name, $attachment->getName()); $this->assertEquals($mimeType, $attachment->getMimeType()); $this->assertEquals(\Jyxo\Mail\Email\Attachment::DISPOSITION_ATTACHMENT, $attachment->getDisposition()); $this->assertFalse($attachment->isInline()); $this->assertEquals('', $attachment->getCid()); $this->assertEquals('', $attachment->getEncoding()); }
function fromRequest() { $data = parent::fromRequest(); $fields = $this->meta['fields']; if (array_key_exists('mime_type', $fields) && array_key_exists('from_db', $fields) && array_key_exists('content', $fields)) { switch (true) { case !empty($data['mime_type']): break; case !empty($data['content']['type']): $data['mime_type'] = $data['content']['type']; break; } if (!empty($data['content']['tmp_name'])) { //Mime type first if (empty($data['mime_type'])) { $data['mime_type'] = File::getMimeType($data['content']['tmp_name'], $this->default_type); } $data['meta_info'] = $this->getMetaInfo(array($data['content']['tmp_name'], $data['content']['name'])); //Overwrite content with file contents if ($data['from_db']) { $data['content'] = file_get_contents($data['content']['tmp_name']); } else { $folder = self::checkUploadFolder($this->meta['table']); if ($folder) { //We add the timestamp to ensure that the name is unique $destination = $folder . time() . '.' . basename($data['content']['name']); if (move_uploaded_file($data['content']['tmp_name'], $destination)) { $data['content'] = $destination; } else { Backend::addError('Could not upload file'); $data = false; } } else { $data = false; } } } } return $data; }
/** * Make the text under the image to say what size preview * * @param $params Array parameters for thumbnail * @param $sizeLinkBigImagePreview HTML for the current size * @return string HTML output */ private function getThumbPrevText($params, $sizeLinkBigImagePreview) { if ($sizeLinkBigImagePreview) { // Show a different message of preview is different format from original. $previewTypeDiffers = false; $origExt = $thumbExt = $this->displayImg->getExtension(); if ($this->displayImg->getHandler()) { $origMime = $this->displayImg->getMimeType(); $typeParams = $params; $this->displayImg->getHandler()->normaliseParams($this->displayImg, $typeParams); list($thumbExt, $thumbMime) = $this->displayImg->getHandler()->getThumbType($origExt, $origMime, $typeParams); if ($thumbMime !== $origMime) { $previewTypeDiffers = true; } } if ($previewTypeDiffers) { return $this->getContext()->msg('show-big-image-preview-differ')->rawParams($sizeLinkBigImagePreview)->params(strtoupper($origExt))->params(strtoupper($thumbExt))->parse(); } else { return $this->getContext()->msg('show-big-image-preview')->rawParams($sizeLinkBigImagePreview)->parse(); } } else { return ''; } }
/** * Check if the file is smaller than the maximum image area for thumbnailing. * * Runs the 'BitmapHandlerCheckImageArea' hook. * * @param File $file * @param array $params * @return bool * @since 1.25 */ public function isImageAreaOkForThumbnaling($file, &$params) { global $wgMaxImageArea; # For historical reasons, hook starts with BitmapHandler $checkImageAreaHookResult = null; Hooks::run('BitmapHandlerCheckImageArea', array($file, &$params, &$checkImageAreaHookResult)); if (!is_null($checkImageAreaHookResult)) { // was set by hook, so return that value return (bool) $checkImageAreaHookResult; } $srcWidth = $file->getWidth($params['page']); $srcHeight = $file->getHeight($params['page']); if ($srcWidth * $srcHeight > $wgMaxImageArea && !($file->getMimeType() == 'image/jpeg' && $this->getScalerType(false, false) == 'im')) { # Only ImageMagick can efficiently downsize jpg images without loading # the entire file in memory return false; } return true; }
/** * writeViewData * @param File $objFile * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ private function writeViewData(File &$objFile) { $this->core->logger->debug('media->controllers->UploadController->writeViewData()'); $this->view->assign('fileId', $objFile->getId()); $this->view->assign('fileFileId', $objFile->getFileId()); $this->view->assign('fileExtension', $objFile->getExtension()); $this->view->assign('fileTitle', $objFile->getTitle()); $this->view->assign('mimeType', $objFile->getMimeType()); $this->view->assign('strDefaultDescription', 'Beschreibung hinzufügen...'); // TODO : guiTexts $this->view->assign('languageId', 1); // TODO : language }
/** * Used instead of getShortDesc if there is no handler registered for file. * * @param File $file * @return string */ static function getGeneralLongDesc($file) { global $wgLang; return wfMessage('file-info', $wgLang->formatSize($file->getSize()), $file->getMimeType())->parse(); }
/** * @param File $file * @return string */ function getLongDesc($file) { global $wgLang; $pages = $file->pageCount(); $size = htmlspecialchars($wgLang->formatSize($file->getSize())); if ($pages === false || $pages <= 1) { $msg = wfMessage('file-info-size')->numParams($file->getWidth(), $file->getHeight())->params($size, '<span class="mime-type">' . $file->getMimeType() . '</span>')->parse(); } else { $msg = wfMessage('file-info-size-pages')->numParams($file->getWidth(), $file->getHeight())->params($size, '<span class="mime-type">' . $file->getMimeType() . '</span>')->numParams($pages)->parse(); } return $msg; }
/** * @param string $path * @return resource GD image * @throws Exception */ private static function createFromFileByMime($path) { $mime = File::getMimeType($path); switch ($mime) { case 'image/jpeg': $img = imagecreatefromjpeg($path); break; case 'image/gif': $img = imagecreatefromgif($path); break; case 'image/png': $img = imagecreatefrompng($path); break; default: throw new Exception('can`t create thumbnail: unknown image type'); } if (!$img) { throw new Exception('can`t create thumbnail: can`t create image handle from file ' . $path); } return $img; }
/** * Checks if file extensions are compatible * * @param $old File Old file * @param $new string New name * * @return bool|null */ static function checkExtensionCompatibility(File $old, $new) { $oldMime = $old->getMimeType(); $n = strrpos($new, '.'); $newExt = self::normalizeExtension($n ? substr($new, $n + 1) : ''); $mimeMagic = MimeMagic::singleton(); /** Wikia change start, author Jacek Jursza, bug id: 31194 - not able to rename video files **/ $result = $mimeMagic->isMatchingExtension($newExt, $oldMime); wfRunHooks('File::checkExtensionCompatibilityResult', array(&$result, &$old, &$oldMime, &$newExt)); return $result; /** Wikia change end **/ }
/** * Return the appropriate im_XXX2vips handler for this file * @param File $file * @return mixed String or false */ public static function getVipsHandler( $file ) { list( $major, $minor ) = File::splitMime( $file->getMimeType() ); if ( $major == 'image' && in_array( $minor, array( 'jpeg', 'png', 'tiff' ) ) ) { return "im_{$minor}2vips"; } else { return false; } }
public function setFile(File $toSave) { $permissionEngine = PermissionEngine::getInstance(); if (!$permissionEngine->currentUserCanDo('uploadFile')) { return false; } $database = Database::getInstance(); if (!$database->isConnected()) { return false; } $validator = new checkIfKnownMimeType(); if (!$validator->validate($toSave->getMimeType())) { return false; } if (!is_readable($toSave->getLocation())) { return false; } $id = $database->escapeString($toSave->getID()); $dateUploaded = $database->escapeString($toSave->getUploadedDate()->format('Y-m-d H:i:s')); $title = $database->escapeString(strip_tags($toSave->getTitle())); $mimeType = $database->escapeString($toSave->getMimeType()); $size = $database->escapeString($toSave->getSize()); $location = $database->escapeString($toSave->getLocation()); $nodeID = $database->escapeString($toSave->getNodeID()); $uploader = $database->escapeString($toSave->getUploaderID()); $folder = $database->escapeString($toSave->getFolderID()); $result = $database->updateTable('file', "uploaded='{$dateUploaded}', title='{$title}', mimeType='{$mimeType}', size={$size}, location='{$location}', nodeID={$nodeID}, uploader={$uploader}, folderID={$folder}", "fileID='{$id}'"); if ($result === false) { return false; } return true; }
/** * Used instead of getLongDesc if there is no handler registered for file. * * @param File $file * @return string */ static function getGeneralLongDesc($file) { return wfMessage('file-info')->sizeParams($file->getSize())->params($file->getMimeType())->parse(); }
/** * Checks if file extensions are compatible * * @param $old File Old file * @param string $new New name * * @return bool|null */ static function checkExtensionCompatibility(File $old, $new) { $oldMime = $old->getMimeType(); $n = strrpos($new, '.'); $newExt = self::normalizeExtension($n ? substr($new, $n + 1) : ''); $mimeMagic = MimeMagic::singleton(); return $mimeMagic->isMatchingExtension($newExt, $oldMime); }
/** * Try to post new file to Geoserver. * * @param File $file The file. * * @return void. */ public function afterInsertFile($file) { // Is the image a tiff? if ($file->getMimeType() == 'image/tiff') { // Get the active server. $server = $this->serversTable->getActiveServer(); // Throw file at Geoserver. if ($server && _putFileToGeoserver($file, $server)) { // Get parent item and WMS. $item = $file->getItem(); $wms = $this->servicesTable->findByItem($item); // If no WMS exists, create one for the file that // was just uploaded to Geoserver. if (!$wms) { $this->servicesTable->createFromFileAndServer($file, $server); } else { if ($wms->address == $server->getWmsAddress()) { // If a WMS already exists and the address is the // same as the address of the active server, append // the new layer to the active layers list. $wms->layers .= ',' . nlwms_layerName($server, $file); $wms->save(); } } } } }
/** * @param File $img * @param $width * @param $height * @return String */ private function getLegacyUrl($img, $width, $height) { $issvg = false; $mime = strtolower($img->getMimeType()); if ($mime == 'image/svg+xml' || $mime == 'image/svg') { $issvg = true; } $sPrefix = ''; if (WikiaFileHelper::isVideoFile($img)) { // videos has different thumbnail markup $sPrefix = 'v,000000,'; } $url = wfReplaceImageServer($img->getThumbUrl($sPrefix . $this->getCut($width, $height) . "-" . $img->getName() . ($issvg ? ".png" : ""))); wfProfileOut(__METHOD__); return $url; }
/** @covers \phpDocumentor\Fileset\File::getMimeType() */ public function testGetMimeTypeWithValidSplFileInfoObjectOfTestTextFile() { if (false === extension_loaded('fileinfo')) { $this->markTestSkipped('Does not apply if fileinfo is not loaded.'); } $file = new File(new \SplFileInfo($this->getNameOfDataDir() . 'fileWithText.txt')); $this->assertEquals('text/plain', $file->getMimeType()); }
/** * writeViewData * @param File $objFile * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ private function writeViewData(File &$objFile) { $this->core->logger->debug('media->controllers->UploadController->writeViewData()'); $this->view->assign('fileId', $objFile->getId()); $this->view->assign('fileFileId', $objFile->getFileId()); $this->view->assign('fileExtension', $objFile->getExtension()); $this->view->assign('fileTitle', $objFile->getTitle()); $this->view->assign('fileVersion', $objFile->getVersion()); $this->view->assign('filePath', sprintf($this->core->sysConfig->media->paths->icon32, $objFile->getSegmentPath())); $this->view->assign('mimeType', $objFile->getMimeType()); $this->view->assign('strDefaultDescription', $this->core->translate->_('Add_description_')); $this->view->assign('languageId', $this->intLanguageId); }
/** * Reset the video thumbnail to its original image as defined by the video provider. * @param File $file The video file to reset * @param string|null $thumbnailUrl * @param int $delayIndex Corresponds to a delay for a job to be queued up if we aren't * able to reset the thumbnail. This index corresponds to a class constant kept in the * ApiWrapper classes. * @return FileRepoStatus The status of the publish operation */ public function resetVideoThumb(File $file, $thumbnailUrl = null, $delayIndex = 0) { $mime = $file->getMimeType(); list(, $provider) = explode('/', $mime); $videoId = $file->getVideoId(); $title = $file->getTitle(); $oUploader = new VideoFileUploader(); $oUploader->setProvider($provider); $oUploader->setVideoId($videoId); $oUploader->setTargetTitle($title->getDBkey()); if (empty($thumbnailUrl)) { $thumbnailUrl = $oUploader->getApiWrapper()->getThumbnailUrl(); } $result = $oUploader->resetThumbnail($file, $thumbnailUrl, $delayIndex); if ($result->isGood()) { // update data and clear cache $status = $this->updateThumbnailData($file); if (!$status->isGood()) { $result->fatal($status->getMessage()); } } return $result; }
/** * Used instead of getLongDesc if there is no handler registered for file. * * @param File $file * @return string */ static function getGeneralLongDesc($file) { return wfMessage('file-info')->sizeParams($file->getSize())->params('<span class="mime-type">' . $file->getMimeType() . '</span>')->parse(); }
/** * Get the MIME type of this file * * @return string mime type */ public function getMimeType() { return $this->originalFile->getMimeType(); }