当前位置: 首页>>代码示例>>PHP>>正文


PHP eZMimeType::findByFileContents方法代码示例

本文整理汇总了PHP中eZMimeType::findByFileContents方法的典型用法代码示例。如果您正苦于以下问题:PHP eZMimeType::findByFileContents方法的具体用法?PHP eZMimeType::findByFileContents怎么用?PHP eZMimeType::findByFileContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eZMimeType的用法示例。


在下文中一共展示了eZMimeType::findByFileContents方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: copyImagesToDB

function copyImagesToDB($remove)
{
    global $cli, $fileHandler;
    $db = eZDB::instance();
    $cli->output("Importing images and imagealiases files to database:");
    $rows = $db->arrayQuery('select filepath from ezimagefile');
    foreach ($rows as $row) {
        $filePath = $row['filepath'];
        $cli->output("- " . $filePath);
        $mimeData = eZMimeType::findByFileContents($filePath);
        $fileHandler->fileStore($filePath, 'image', $remove, $mimeData['name']);
    }
}
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:13,代码来源:clusterize.php

示例2: imageAliasInfo

    /**
     * Image information for $aliasName. This is the information which normally
     * would be provided during generation of aliasName. This so that requests
     * not holding the lock will provide meaningful information.
     *
     * @param mixed $mimeData
     * @param string $aliasName
     * @return array
     */
    function imageAliasInfo( $mimeData, $aliasName, $isAliasNew = false )
    {
        if ( is_string( $mimeData ) )
            $mimeData = eZMimeType::findByFileContents( $mimeData );

        $this->analyzeImage( $mimeData );
        if ( $aliasName )
        {
            $aliasList = $this->aliasList();
            if ( isset( $aliasList[$aliasName] ) )
            {
                $alias = $aliasList[$aliasName];
                if ( $alias['mime_type'] )
                {
                    eZMimeType::changeMIMEType( $mimeData, $alias['mime_type'] );
                }
            }
        }
        if ( $aliasName != 'original' )
        {
            $mimeData['filename'] = $mimeData['basename'] . '_' . $aliasName . '.' . $mimeData['suffix'];
            $mimeData['url'] = $mimeData['dirpath'] . '/' . $mimeData['filename'];
        }
        // eZDebug::writeDebug( $mimeData, __METHOD__ );
        return $mimeData;
    }
开发者ID:nottavi,项目名称:ezpublish,代码行数:35,代码来源:ezimagemanager.php

示例3: validateImageFiles

    function validateImageFiles( $package, $http, $currentStepID, &$stepMap, &$persistentData, &$errorList )
    {
        // If we don't have an image we continue as normal
        if ( !eZHTTPFile::canFetch( 'PackageImageFile' ) )
            return true;

        $file = eZHTTPFile::fetch( 'PackageImageFile' );

        $result = true;
        if ( $file )
        {
            $mimeData = eZMimeType::findByFileContents( $file->attribute( 'original_filename' ) );
            $dir = eZSys::storageDirectory() .  '/temp';
            eZMimeType::changeDirectoryPath( $mimeData, $dir );
            $file->store( false, false, $mimeData );
            $persistentData['imagefiles'][] = $mimeData;
            $result = false;
        }
        return $result;
    }
开发者ID:nottavi,项目名称:ezpublish,代码行数:20,代码来源:ezstylepackagecreator.php

示例4: fetchVirtualSiteContent

    function fetchVirtualSiteContent( $site, $depth, $properties )
    {
        $this->appendLogEntry( "Script URL.." . eZSys::instance()->RequestURI, 'CS:fetchVirtualSiteContent' );
        // Location of the info file.
        $infoFile = $_SERVER['DOCUMENT_ROOT'] . '/' . eZWebDAVContentServer::virtualInfoFileName();

        // Always add the current collection
        $contentEntry = array();
        $contentEntry["name"]     = eZSys::instance()->RequestURI;
        $contentEntry["size"]     = 0;
        $contentEntry["mimetype"] = 'httpd/unix-directory';
        $contentEntry["ctime"]    = filectime( 'settings/siteaccess/' . $site );
        $contentEntry["mtime"]    = filemtime( 'settings/siteaccess/' . $site );
        $contentEntry["href"]     = eZSys::instance()->RequestURI;
        $entries[] = $contentEntry;

        $defctime = $contentEntry['ctime'];
        $defmtime = $contentEntry['mtime'];

        if ( $depth > 0 )
        {
            $scriptURL = eZSys::instance()->RequestURI;
            if ( $scriptURL{strlen($scriptURL) - 1} != "/" )
                $scriptURL .= "/";

            // Set up attributes for the virtual content folder:
            foreach ( $this->virtualInfoList() as $info )
            {
                $name = $info['name'];
                $filepath = false;
                if ( isset( $info['filepath'] ) )
                    $filepath = $info['filepath'];
                $size = 0;
                if ( $filepath === false or file_exists( $filepath ) )
                {
                    $mimeType = 'httpd/unix-directory';
                    if ( $filepath !== false )
                    {
                        $mimeInfo = eZMimeType::findByFileContents( $filepath );
                        $mimeType = $mimeInfo['name'];
                        $ctime = filectime( $filepath );
                        $mtime = filemtime( $filepath );
                        $size  = filesize( $filepath );
                    }
                    else
                    {
                        $ctime = $defctime;
                        $mtime = $defmtime;
                    }

                    $entry             = array();
                    $entry["name"]     = $name;
                    $entry["size"]     = $size;
                    $entry["mimetype"] = $mimeType;
                    $entry["ctime"]    = $ctime;
                    $entry["mtime"]    = $mtime;
                    $entry["href"]     = $scriptURL . $name;
                    $entries[]         = $entry;
                }
            }
        }

        return $entries;
    }
开发者ID:nottavi,项目名称:ezpublish,代码行数:64,代码来源:ezwebdavcontentserver.php

示例5: callImage

 /**
  * Function for insert image
  */
 function callImage($info)
 {
     $params = array();
     $leftMargin = false;
     $rightMargin = false;
     eZPDFTable::extractParameters($info['p'], 0, $params, true);
     $filename = rawurldecode($params['src']);
     $mimetype = eZMimeType::findByFileContents($filename);
     $this->transaction('start');
     if (!isset($params['static'])) {
         $params['static'] = false;
     }
     if ($this->yOffset() - $params['height'] < $this->ez['bottomMargin']) {
         $this->ezNewPage();
     }
     if (isset($params['dpi'])) {
         $newWidth = (int) ($params['width'] * ((int) $params['dpi'] / 72));
         $newHeight = (int) ($params['height'] * ((int) $params['dpi'] / 72));
         $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg';
         while (file_exists($newFilename)) {
             $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg';
         }
         $img = eZImageManager::factory();
         $newImg = $img->convert($filename, $newFilename, false, array('filters' => array(array('name' => 'geometry/scaledownonly', 'data' => array($newWidth, $newHeight)))));
         $filename = $newFilename['url'];
     }
     $drawableAreaWidth = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $this->ez['rightMargin'];
     switch ($params['align']) {
         case 'right':
             $xOffset = $this->ez['pageWidth'] - ($this->rightMargin() + $params['width']);
             $rightMargin = $this->rightMargin() + $params['width'];
             if ($rightMargin > $drawableAreaWidth + $this->rightMargin()) {
                 // the image is equal or larger then width of the page(of the drawable area) => no point
                 // to set $rightMargin and next object(text, image, ...) should be outputted below the image.
                 $rightMargin = false;
             }
             break;
         case 'center':
             $xOffset = ($this->ez['pageWidth'] - $this->rightMargin() - $this->leftMargin()) / 2 + $this->leftMargin() - $params['width'] / 2;
             break;
         case 'left':
         default:
             $xOffset = $this->leftMargin();
             $leftMargin = $this->leftMargin() + $params['width'];
             if ($leftMargin > $drawableAreaWidth + $this->leftMargin()) {
                 // the image is equal or larger then width of the page(of the drawable area) => no point
                 // to set $leftMargin and next object(text, image, ...) should be outputted below the image.
                 $leftMargin = false;
             }
             break;
     }
     if (isset($params['x'])) {
         $xOffset = $params['x'];
         $leftMargin = false;
         $rightMargin = false;
     }
     $yOffset = $this->yOffset();
     $whileCount = 0;
     if ($params['width'] < $drawableAreaWidth) {
         while ($this->leftMargin($yOffset) > $xOffset && ++$whileCount < 100) {
             $yOffset -= 10;
         }
     }
     $yOffset -= $params['height'];
     $yOffset += $this->lineHeight() / 2;
     if (isset($params['y'])) {
         $yOffset = $params['y'];
     }
     if ($leftMargin !== false) {
         $this->setLimitedLeftMargin($yOffset - 7, $yOffset + $params['height'] + 7, $leftMargin + 7);
     }
     if ($rightMargin !== false) {
         $this->setLimitedRightMargin($yOffset - 7, $yOffset + $params['height'] + 7, $rightMargin + 7);
     }
     switch ($mimetype['name']) {
         case 'image/gif':
             $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg';
             while (file_exists($newFilename)) {
                 $newFilename = eZSys::cacheDirectory() . '/' . md5(mt_rand()) . '.jpg';
             }
             $newMimetype = eZMimeType::findByURL($newFilename);
             $img = eZImageManager::factory();
             $newImg = $img->convert($mimetype, $newMimetype, false, array());
             $this->addJpegFromFile($newMimetype['url'], $xOffset, $yOffset, $params['width'], $params['height']);
             break;
         case 'image/jpeg':
             $this->addJpegFromFile($filename, $xOffset, $yOffset, $params['width'], $params['height']);
             break;
         case 'image/png':
             if ($this->addPngFromFile($filename, $xOffset, $yOffset, $params['width'], $params['height']) === false) {
                 $this->transaction('abort');
                 return;
             }
             break;
         default:
             eZDebug::writeError('Unsupported image file type, ' . $mimetype['name'], __METHOD__);
             $this->transaction('abort');
//.........这里部分代码省略.........
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:101,代码来源:class.ezpdftable.php

示例6: fetchHTTPFile

 /**
  * Fetches the HTTP-File into $file and fills in MIME-Type information into $mimeData.
  *
  * @return bool false if something went wrong.
  */
 function fetchHTTPFile($httpFileIdentifier, &$errors, &$file, &$mimeData)
 {
     $returnCode = eZHTTPFile::canFetch($httpFileIdentifier, 0);
     if ($returnCode !== eZHTTPFile::UPLOADEDFILE_OK && $returnCode !== true) {
         switch ($returnCode) {
             case eZHTTPFile::UPLOADEDFILE_DOES_NOT_EXIST:
                 $errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'A file is required for upload, no file were found.'));
                 break;
             case eZHTTPFile::UPLOADEDFILE_EXCEEDS_PHP_LIMIT:
             case eZHTTPFile::UPLOADEDFILE_EXCEEDS_MAX_SIZE:
                 $errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'The uploaded file size is above the maximum limit.'));
                 break;
             case eZHTTPFile::UPLOADEDFILE_MISSING_TMP_DIR:
             case eZHTTPFile::UPLOADEDFILE_CANT_WRITE:
             case eZHTTPFile::UPLOADEDFILE_UNKNOWN_ERROR:
                 $errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'A system error occured while writing the uploaded file.'));
                 break;
         }
         return false;
     }
     $file = eZHTTPFile::fetch($httpFileIdentifier);
     if (!$file instanceof eZHTTPFile) {
         $errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'Expected a eZHTTPFile object but got nothing.'));
         return false;
     }
     $mimeData = eZMimeType::findByFileContents($file->attribute("original_filename"));
     return true;
 }
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:33,代码来源:ezcontentupload.php

示例7: storedFilename

 function storedFilename(&$binary, $returnMimeData = false)
 {
     $origDir = eZSys::storageDirectory() . '/original';
     $class = get_class($binary);
     $fileName = false;
     $originalFilename = false;
     if (in_array($class, array('eZBinaryFile', 'eZMedia'))) {
         $fileName = $origDir . "/" . $binary->attribute('mime_type_category') . '/' . $binary->attribute("filename");
         $originalFilename = $binary->attribute('original_filename');
     } else {
         if ($class == 'eZImageAliasHandler') {
             $alias = $binary->attribute('original');
             if ($alias) {
                 $fileName = $alias['url'];
             }
             $originalFilename = $binary->attribute('original_filename');
         }
     }
     if ($fileName) {
         $mimeData = eZMimeType::findByFileContents($fileName);
         $mimeData['original_filename'] = $originalFilename;
         if (!isset($mimeData['name'])) {
             $mimeData['name'] = 'application/octet-stream';
         }
         if ($returnMimeData) {
             return $mimeData;
         } else {
             return $mimeData['url'];
         }
     }
     return false;
 }
开发者ID:runelangseid,项目名称:ezpublish,代码行数:32,代码来源:ezbinaryfilehandler.php

示例8: generateXMLData

 function generateXMLData()
 {
     $doc = new DOMDocument('1.0', 'utf-8');
     $imageNode = $doc->createElement("ezimage");
     $doc->appendChild($imageNode);
     $fileName = false;
     $imageManager = eZImageManager::factory();
     $mimeData = eZMimeType::findByFileContents($fileName);
     $imageManager->analyzeImage($mimeData);
     $imageNode->setAttribute('serial_number', false);
     $imageNode->setAttribute('is_valid', false);
     $imageNode->setAttribute('filename', $fileName);
     $imageNode->setAttribute('suffix', false);
     $imageNode->setAttribute('basename', false);
     $imageNode->setAttribute('dirpath', false);
     $imageNode->setAttribute('url', false);
     $imageNode->setAttribute('original_filename', false);
     $imageNode->setAttribute('mime_type', false);
     $imageNode->setAttribute('width', false);
     $imageNode->setAttribute('height', false);
     $imageNode->setAttribute('alternative_text', false);
     $imageNode->setAttribute('alias_key', $imageManager->createImageAliasKey($imageManager->alias('original')));
     $imageNode->setAttribute('timestamp', time());
     $this->createImageInformationNode($imageNode, $mimeData);
     $this->storeDOMTree($doc, true, false);
 }
开发者ID:,项目名称:,代码行数:26,代码来源:

示例9: insertRegularFile

    function insertRegularFile( $object, $objectVersion, $objectLanguage,
                                $objectAttribute, $filePath,
                                &$result )
    {
        $result = array( 'errors' => array(),
                         'require_storage' => false );
        $attributeID = $objectAttribute->attribute( 'id' );

        $binary = eZBinaryFile::fetch( $attributeID, $objectVersion );
        if ( $binary === null )
            $binary = eZBinaryFile::create( $attributeID, $objectVersion );

        $fileName = basename( $filePath );
        $mimeData = eZMimeType::findByFileContents( $filePath );
        $storageDir = eZSys::storageDirectory();
        list( $group, $type ) = explode( '/', $mimeData['name'] );
        $destination = $storageDir . '/original/' . $group;

        if ( !file_exists( $destination ) )
        {
            if ( !eZDir::mkdir( $destination, false, true ) )
            {
                return false;
            }
        }

        // create dest filename in the same manner as eZHTTPFile::store()
        // grab file's suffix
        $fileSuffix = eZFile::suffix( $fileName );
        // prepend dot
        if( $fileSuffix )
            $fileSuffix = '.' . $fileSuffix;
        // grab filename without suffix
        $fileBaseName = basename( $fileName, $fileSuffix );
        // create dest filename
        $destFileName = md5( $fileBaseName . microtime() . mt_rand() ) . $fileSuffix;
        $destination = $destination . '/' . $destFileName;

        copy( $filePath, $destination );

        $fileHandler = eZClusterFileHandler::instance();
        $fileHandler->fileStore( $destination, 'binaryfile', true, $mimeData['name'] );


        $binary->setAttribute( "contentobject_attribute_id", $attributeID );
        $binary->setAttribute( "version", $objectVersion );
        $binary->setAttribute( "filename", $destFileName );
        $binary->setAttribute( "original_filename", $fileName );
        $binary->setAttribute( "mime_type", $mimeData['name'] );

        $binary->store();

        $objectAttribute->setContent( $binary );
        return true;
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:55,代码来源:ezbinaryfiletype.php

示例10: time

             $newBaseName = $objectName;
         }
         if ($newFilePath != $filePath) {
             if (!file_exists($newDirPath)) {
                 eZDir::mkdir($newDirPath, false, true);
             }
             eZFileHandler::copy($filePath, $newFilePath);
             $filePath = $newFilePath;
             $fileName = $newFileName;
             $suffix = $newSuffix;
             $dirPath = $newDirPath;
             $baseName = $newBaseName;
         }
     }
 }
 $mimeData = eZMimeType::findByFileContents($fileName);
 $imageManager->analyzeImage($mimeData);
 $imageNode->setAttribute('serial_number', false);
 $imageNode->setAttribute('is_valid', $isValid);
 $imageNode->setAttribute('filename', $fileName);
 $imageNode->setAttribute('suffix', $suffix);
 $imageNode->setAttribute('basename', $baseName);
 $imageNode->setAttribute('dirpath', $dirPath);
 $imageNode->setAttribute('url', $filePath);
 $imageNode->setAttribute('original_filename', $originalFileName);
 $imageNode->setAttribute('mime_type', $mimeType);
 $imageNode->setAttribute('width', $width);
 $imageNode->setAttribute('height', $height);
 $imageNode->setAttribute('alternative_text', $altText);
 $imageNode->setAttribute('alias_key', $imageManager->createImageAliasKey($imageManager->alias('original')));
 $imageNode->setAttribute('timestamp', time());
开发者ID:CG77,项目名称:ezpublish-legacy,代码行数:31,代码来源:updateimagesystem.php

示例11: insertRegularFile

 function insertRegularFile($object, $objectVersion, $objectLanguage, $objectAttribute, $filePath, &$result)
 {
     $result = array('errors' => array(), 'require_storage' => false);
     $attributeID = $objectAttribute->attribute('id');
     $media = eZMedia::fetch($attributeID, $objectVersion);
     if ($media === null) {
         $media = eZMedia::create($attributeID, $objectVersion);
     }
     $fileName = basename($filePath);
     $mimeData = eZMimeType::findByFileContents($filePath);
     $storageDir = eZSys::storageDirectory();
     list($group, $type) = explode('/', $mimeData['name']);
     $destination = $storageDir . '/original/' . $group;
     if (!file_exists($destination)) {
         if (!eZDir::mkdir($destination, false, true)) {
             return false;
         }
     }
     // create dest filename in the same manner as eZHTTPFile::store()
     // grab file's suffix
     $fileSuffix = eZFile::suffix($fileName);
     // prepend dot
     if ($fileSuffix) {
         $fileSuffix = '.' . $fileSuffix;
     }
     // grab filename without suffix
     $fileBaseName = basename($fileName, $fileSuffix);
     // create dest filename
     $destFileName = md5($fileBaseName . microtime() . mt_rand()) . $fileSuffix;
     $destination = $destination . '/' . $destFileName;
     copy($filePath, $destination);
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileStore($destination, 'mediafile', true, $mimeData['name']);
     $classAttribute = $objectAttribute->contentClassAttribute();
     $player = $classAttribute->attribute("data_text1");
     $pluginPage = eZMediaType::pluginPage($player);
     $media->setAttribute("contentobject_attribute_id", $attributeID);
     $media->setAttribute("version", $objectVersion);
     $media->setAttribute("filename", $destFileName);
     $media->setAttribute("original_filename", $fileName);
     $media->setAttribute("mime_type", $mimeData['name']);
     // Setting width and height to zero means that the browser/player must find the size itself.
     // In the future we will probably analyze the media file and find this information
     $width = $height = 0;
     // Quality is not known, so we don't set any
     $quality = false;
     // Not sure what this is for, set to false
     $controls = false;
     // We want to show controllers by default
     $hasController = true;
     // Don't play automatically
     $isAutoplay = false;
     // Don't loop movie
     $isLoop = false;
     $media->setAttribute("width", $width);
     $media->setAttribute("height", $height);
     $media->setAttribute("quality", $quality);
     $media->setAttribute("controls", $controls);
     $media->setAttribute("pluginspage", $pluginPage);
     $media->setAttribute("is_autoplay", $isAutoplay);
     $media->setAttribute("has_controller", $hasController);
     $media->setAttribute("is_loop", $isLoop);
     $media->store();
     $objectAttribute->setContent($media);
     return true;
 }
开发者ID:mugoweb,项目名称:ezpublish-legacy,代码行数:66,代码来源:ezmediatype.php

示例12: passthrough

 /**
  * Outputs file contents prepending them with appropriate HTTP headers.
  *
  * \public
  */
 function passthrough()
 {
     $path = $this->filePath;
     eZDebugSetting::writeDebug('kernel-clustering', "fs::passthrough()", __METHOD__);
     eZDebug::accumulatorStart('dbfile', false, 'dbfile');
     $mimeData = eZMimeType::findByFileContents($path);
     //        $mimeType = $mimeData['name'];
     $mimeType = 'application/octec-stream';
     $contentLength = filesize($path);
     header("Content-Length: {$contentLength}");
     header("Content-Type: {$mimeType}");
     header("Expires: " . gmdate('D, d M Y H:i:s', time() + 6000) . 'GMT');
     header("Connection: close");
     readfile($path);
     eZDebug::accumulatorStop('dbfile');
 }
开发者ID:runelangseid,项目名称:ezpublish,代码行数:21,代码来源:ezfsfilehandler.php

示例13: fetchHTTPFile

 function fetchHTTPFile($httpFileIdentifier, &$errors, &$file, &$mimeData)
 {
     if (!eZHTTPFile::canFetch($httpFileIdentifier)) {
         $errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'A file is required for upload, no file were found.'));
         return false;
     }
     $file = eZHTTPFile::fetch($httpFileIdentifier);
     if (!$file instanceof eZHTTPFile) {
         $errors[] = array('description' => ezpI18n::tr('kernel/content/upload', 'Expected a eZHTTPFile object but got nothing.'));
         return false;
     }
     $mimeData = eZMimeType::findByFileContents($file->attribute("original_filename"));
     return false;
 }
开发者ID:runelangseid,项目名称:ezpublish,代码行数:14,代码来源:ezcontentupload.php

示例14: fetchCollectionAttributeHTTPInput

 function fetchCollectionAttributeHTTPInput($collection, $collectionAttribute, $http, $base, $contentObjectAttribute)
 {
     EnhancedeZBinaryFileType::checkFileUploads();
     if (eZHTTPFile::canFetch($base . "_data_enhancedbinaryfilename_" . $contentObjectAttribute->attribute("id")) != eZHTTPFile::UPLOADEDFILE_OK) {
         return false;
     }
     //Check allowed file type - must do it here,again - otherwise an illegal
     //file will still be created in the storage directory
     $binaryFile = eZHTTPFile::fetch($base . "_data_enhancedbinaryfilename_" . $contentObjectAttribute->attribute("id"));
     if (!$binaryFile) {
         return eZInputValidator::STATE_INVALID;
     }
     $moduleINI = eZINI::instance('module.ini.append.php', 'settings');
     $allowed = $moduleINI->variable('AllowedFileTypes', 'AllowedFileTypeList');
     // $binaryFile->attribute( 'mime_type_part' ) not always the extension
     $extension = preg_replace('/.*\\.(.+?)$/', '\\1', $binaryFile->attribute("original_filename"));
     if (!in_array(strtolower($extension), $allowed)) {
         $contentObjectAttribute->setValidationError(ezpI18n::tr('kernel/classes/datatypes', 'Failed to store file. Only the following file types are allowed: %1.'), implode(", ", $allowed));
         return eZInputValidator::STATE_INVALID;
     }
     //$contentObjectAttribute->setContent( $binaryFile );
     if ($binaryFile instanceof eZHTTPFile) {
         //clean up older files.
         $moduleINI = eZINI::instance('module.ini.append.php', 'settings');
         $maxFiles = $moduleINI->variable('RemoveFiles', 'MaxFiles');
         $downloadPath = $moduleINI->variable('RemoveFiles', 'DownloadPath');
         $downloadPath = trim($downloadPath, "/");
         if (!$downloadPath) {
             $downloadPath = 'original/collected';
         }
         if ($maxFiles > 0) {
             $Files = array();
             $storageDir = eZSys::storageDirectory();
             $fileCollection = eZDir::recursiveFindRelative($storageDir, $downloadPath, '.*');
             if (count($fileCollection) >= $maxFiles) {
                 foreach ($fileCollection as $fileItem) {
                     $lastModified = filemtime($storageDir . '/' . $fileItem);
                     $Files[$fileItem] = filemtime($storageDir . '/' . $fileItem);
                 }
                 asort($Files, SORT_NUMERIC);
                 while (count($Files) >= $maxFiles) {
                     $removeFile = key($Files);
                     if (file_exists($storageDir . '/' . $removeFile)) {
                         if (!unlink($storageDir . '/' . $removeFile)) {
                             eZDebug::writeError("Failed to delete file: " . $storageDir . '/' . $removeFile, "EnhancedeZBinaryFileType");
                             return false;
                         }
                     }
                     array_shift($Files);
                 }
             }
         }
         //end cleanup
         // $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
         //$version = $contentObjectAttribute->attribute( "version" );
         $mimeData = eZMimeType::findByFileContents($binaryFile->attribute("original_filename"));
         //Nice name but it still uses the extension to set the mimetype and therefore can be bogus
         $mime = $mimeData['name'];
         if ($mime == '') {
             $mime = $binaryFile->attribute("mime_type");
         }
         $extension = eZFile::suffix($binaryFile->attribute("original_filename"));
         $binaryFile->setMimeType($mime);
         if (!$binaryFile->store($downloadPath, $extension)) {
             eZDebug::writeError("Failed to store http-file: " . $binaryFile->attribute("original_filename"), "EnhancedeZBinaryFileType");
             return false;
         }
         //Adds xmltext to collection attribute with file info to data_text attribute
         $doc = new DOMDocument('1.0', 'utf-8');
         $root = $doc->createElement('binaryfile-info');
         $binaryFileList = $doc->createElement('binaryfile-attributes');
         foreach ($binaryFile as $key => $binaryFileItem) {
             $binaryFileElement = $doc->createElement($key, $binaryFileItem);
             $binaryFileList->appendChild($binaryFileElement);
         }
         $root->appendChild($binaryFileList);
         $doc->appendChild($root);
         $docText = EnhancedeZBinaryFileType::domString($doc);
         $collectionAttribute->setAttribute('data_text', $docText);
     }
     return true;
 }
开发者ID:Alexnder,项目名称:enhancedezbinaryfile,代码行数:82,代码来源:enhancedezbinaryfiletype.php


注:本文中的eZMimeType::findByFileContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。