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


PHP String::mime_content_type方法代码示例

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


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

示例1: downloadFile

 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $mediaType string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $mediaType = null, $inline = false, $fileName = null)
 {
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result, &$fileName))) {
         return $result;
     }
     if (is_readable($filePath)) {
         if ($mediaType === null) {
             // If the media type wasn't specified, try to detect.
             $mediaType = String::mime_content_type($filePath);
             if (empty($mediaType)) {
                 $mediaType = 'application/octet-stream';
             }
         }
         if ($fileName === null) {
             // If the filename wasn't specified, use the server-side.
             $fileName = basename($filePath);
         }
         Registry::clear();
         // Free some memory
         header("Content-Type: {$mediaType}");
         header('Content-Length: ' . filesize($filePath));
         header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"{$fileName}\"");
         header('Cache-Control: private');
         // Workarounds for IE weirdness
         header('Pragma: public');
         // Beware of converting to instance call
         // https://github.com/pkp/pkp-lib/commit/82f4a36db406ecac3eb88875541a74123e455713#commitcomment-1459396
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
开发者ID:yuricampos,项目名称:ojs,代码行数:42,代码来源:FileManager.inc.php

示例2: downloadFile

 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $mediaType string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $mediaType = null, $inline = false, $fileName = null)
 {
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result, &$fileName))) {
         return $result;
     }
     $postDownloadHookList = array('FileManager::downloadFileFinished', 'UsageEventPlugin::getUsageEvent');
     if (is_readable($filePath)) {
         if ($mediaType === null) {
             // If the media type wasn't specified, try to detect.
             $mediaType = String::mime_content_type($filePath);
             if (empty($mediaType)) {
                 $mediaType = 'application/octet-stream';
             }
         }
         if ($fileName === null) {
             // If the filename wasn't specified, use the server-side.
             $fileName = basename($filePath);
         }
         $postDownloadHooks = null;
         $hooks = HookRegistry::getHooks();
         foreach ($postDownloadHookList as $hookName) {
             if (isset($hooks[$hookName])) {
                 $postDownloadHooks[$hookName] = $hooks[$hookName];
             }
         }
         unset($hooks);
         Registry::clear();
         // Stream the file to the end user.
         header("Content-Type: {$mediaType}");
         header('Content-Length: ' . filesize($filePath));
         header('Content-Disposition: ' . ($inline ? 'inline' : 'attachment') . "; filename=\"{$fileName}\"");
         header('Cache-Control: private');
         // Workarounds for IE weirdness
         header('Pragma: public');
         // Beware of converting to instance call
         // https://github.com/pkp/pkp-lib/commit/82f4a36db406ecac3eb88875541a74123e455713#commitcomment-1459396
         FileManager::readFile($filePath, true);
         if ($postDownloadHooks) {
             foreach ($postDownloadHooks as $hookName => $hooks) {
                 HookRegistry::setHooks($hookName, $hooks);
             }
         }
         $returner = true;
     } else {
         $returner = false;
     }
     HookRegistry::call('FileManager::downloadFileFinished', array(&$returner));
     return $returner;
 }
开发者ID:farhanabbas1983,项目名称:ojs-1,代码行数:58,代码来源:FileManager.inc.php

示例3: _fileMimeType

 function _fileMimeType($filePath)
 {
     return String::mime_content_type($filePath);
 }
开发者ID:artkuo,项目名称:ocs,代码行数:4,代码来源:FilesHandler.inc.php

示例4: downloadFile

 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $mediaType string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $mediaType = null, $inline = false)
 {
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$mediaType, &$inline, &$result))) {
         return $result;
     }
     if (is_readable($filePath)) {
         if ($mediaType == null) {
             $mediaType = String::mime_content_type($filePath);
             if (empty($mediaType)) {
                 $mediaType = 'application/octet-stream';
             }
         }
         Registry::clear();
         // Free some memory
         header("Content-Type: {$mediaType}");
         header("Content-Length: " . filesize($filePath));
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\"");
         header("Cache-Control: private");
         // Workarounds for IE weirdness
         header("Pragma: public");
         import('lib.pkp.classes.file.FileManager');
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
开发者ID:ramonsodoma,项目名称:pkp-lib,代码行数:36,代码来源:FileManager.inc.php

示例5: copyHTMLGalleyImages

 /**
  * Copy all image files for an article's HTML galley.
  * @param $galley ArticleHTMLGalley
  * @param $prefix string image file prefix, e.g. "<abbrev>-<year>-<id>"
  */
 function copyHTMLGalleyImages($galley, $prefix)
 {
     $dir = opendir($this->importPath . '/images/articleimages');
     if (!$dir) {
         printf("Failed to open directory %s\n", $this->importPath . '/images/articleimages');
         return;
         // This should never happen
     }
     while (($file = readdir($dir)) !== false) {
         if (!strstr($file, $prefix . '-')) {
             continue;
         }
         if (!isset($fileManager)) {
             $fileManager =& new ArticleFileManager($galley->getArticleId());
             $galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
             $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
         }
         $fileType = ARTICLE_FILE_PUBLIC;
         $oldPath = $this->importPath . '/images/articleimages/' . $file;
         $mimeType = String::mime_content_type($oldPath);
         if (empty($mimeType)) {
             $extension = $fileManager->getExtension($file);
             if ($extension == 'jpg') {
                 $mimeType = 'image/jpeg';
             } else {
                 $mimeType = 'image/' . $extension;
             }
         }
         $articleFile =& new ArticleFile();
         $articleFile->setArticleId($galley->getArticleId());
         $articleFile->setFileName('temp');
         $articleFile->setOriginalFileName($file);
         $articleFile->setFileType($mimeType);
         $articleFile->setFileSize(filesize($oldPath));
         $articleFile->setType($fileManager->typeToPath($fileType));
         $articleFile->setStatus('');
         $articleFile->setDateUploaded(date('Y-m-d', filemtime($oldPath)));
         $articleFile->setDateModified($articleFile->getDateUploaded());
         $articleFile->setRound(1);
         $articleFile->setRevision(1);
         $fileId = $articleFileDao->insertArticleFile($articleFile);
         $newFileName = $fileManager->generateFilename($articleFile, $fileType, $file);
         if (!$fileManager->copyFile($oldPath, $fileManager->filesDir . $fileManager->typeToPath($fileType) . '/' . $newFileName)) {
             $articleFileDao->deleteArticleFileById($articleFile->getFileId());
             printf("Failed to copy file %s\n", $oldPath);
             // This should never happen
         } else {
             $articleFileDao->updateArticleFile($articleFile);
             $galleyDao->insertGalleyImage($galley->getGalleyId(), $fileId);
         }
     }
     closedir($dir);
 }
开发者ID:Jouper,项目名称:jouper,代码行数:58,代码来源:ImportOJS1.inc.php

示例6: handleUpload

 /**
  * Upload the file and add it to the database.
  * @param $fileName string index into the $_FILES array
  * @param $userId int
  * @return object The new TemporaryFile or false on failure
  */
 function handleUpload($fileName, $userId)
 {
     // Get the file extension, then rename the file.
     $fileExtension = $this->parseFileExtension($this->getUploadedFileName($fileName));
     if (!$this->fileExists($this->getBasePath(), 'dir')) {
         // Try to create destination directory
         $this->mkdirtree($this->getBasePath());
     }
     $newFileName = basename(tempnam($this->getBasePath(), $fileExtension));
     if (!$newFileName) {
         return false;
     }
     if ($this->uploadFile($fileName, $this->getBasePath() . $newFileName)) {
         $temporaryFileDao =& DAORegistry::getDAO('TemporaryFileDAO');
         $temporaryFile = $temporaryFileDao->newDataObject();
         $temporaryFile->setUserId($userId);
         $temporaryFile->setFileName($newFileName);
         $temporaryFile->setFileType(String::mime_content_type($this->getBasePath() . $newFileName));
         $temporaryFile->setFileSize($_FILES[$fileName]['size']);
         $temporaryFile->setOriginalFileName($this->truncateFileName($_FILES[$fileName]['name'], 127));
         $temporaryFile->setDateUploaded(Core::getCurrentDate());
         $temporaryFileDao->insertTemporaryFile($temporaryFile);
         return $temporaryFile;
     } else {
         return false;
     }
 }
开发者ID:EreminDm,项目名称:water-cao,代码行数:33,代码来源:PKPTemporaryFileManager.inc.php

示例7: addAttachment

 /**
  * Adds a file attachment to the email.
  * @param $filePath string complete path to the file to attach
  * @param $fileName string attachment file name (optional)
  * @param $contentType string attachment content type (optional)
  * @param $contentDisposition string attachment content disposition, inline or attachment (optional, default attachment)
  */
 function addAttachment($filePath, $fileName = '', $contentType = '', $contentDisposition = 'attachment')
 {
     if (($attachments =& $this->getData('attachments')) == null) {
         $attachments = array();
     }
     /* If the arguments $fileName and $contentType are not specified,
     			then try and determine them automatically. */
     if (empty($fileName)) {
         $fileName = basename($filePath);
     }
     if (empty($contentType)) {
         $contentType = String::mime_content_type($filePath);
         if (empty($contentType)) {
             $contentType = 'application/x-unknown-content-type';
         }
     }
     // Open the file and read contents into $attachment
     if (is_readable($filePath) && is_file($filePath)) {
         $fp = fopen($filePath, 'rb');
         if ($fp) {
             $content = '';
             while (!feof($fp)) {
                 $content .= fread($fp, 4096);
             }
             fclose($fp);
         }
     }
     if (isset($content)) {
         /* Encode the contents in base64. */
         $content = chunk_split(base64_encode($content), MAIL_WRAP, MAIL_EOL);
         array_push($attachments, array('filename' => $fileName, 'content-type' => $contentType, 'disposition' => $contentDisposition, 'content' => $content));
         return $this->setData('attachments', $attachments);
     } else {
         return false;
     }
 }
开发者ID:ramonsodoma,项目名称:pkp-lib,代码行数:43,代码来源:Mail.inc.php

示例8: foreach


//.........这里部分代码省略.........
             $chronologicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'chronological', $chronological, false);
             if ($chronologicalNode) {
                 XMLCustomWriter::setAttribute($chronologicalNode, 'locale', $locale);
                 $isCoverageNecessary = true;
             }
             unset($chronologicalNode);
         }
     }
     if (is_array($article->getCoverageSample(null))) {
         foreach ($article->getCoverageSample(null) as $locale => $sample) {
             $sampleNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'sample', $sample, false);
             if ($sampleNode) {
                 XMLCustomWriter::setAttribute($sampleNode, 'locale', $locale);
                 $isCoverageNecessary = true;
             }
             unset($sampleNode);
         }
     }
     if ($isCoverageNecessary) {
         XMLCustomWriter::appendChild($indexingNode, $coverageNode);
         $isIndexingNecessary = true;
     }
     if ($isIndexingNecessary) {
         XMLCustomWriter::appendChild($root, $indexingNode);
     }
     /* --- */
     /* --- Authors --- */
     foreach ($article->getAuthors() as $author) {
         $authorNode =& NativeExportDom::generateAuthorDom($doc, $journal, $issue, $article, $author);
         XMLCustomWriter::appendChild($root, $authorNode);
         unset($authorNode);
     }
     /* --- */
     if (is_array($article->getShowCoverPage(null))) {
         foreach (array_keys($article->getShowCoverPage(null)) as $locale) {
             if ($article->getShowCoverPage($locale)) {
                 $coverNode =& XMLCustomWriter::createElement($doc, 'cover');
                 XMLCustomWriter::appendChild($root, $coverNode);
                 XMLCustomWriter::setAttribute($coverNode, 'locale', $locale);
                 XMLCustomWriter::createChildWithText($doc, $coverNode, 'altText', $issue->getCoverPageDescription($locale), false);
                 $coverFile = $article->getFileName($locale);
                 if ($coverFile != '') {
                     $imageNode =& XMLCustomWriter::createElement($doc, 'image');
                     XMLCustomWriter::appendChild($coverNode, $imageNode);
                     import('classes.file.PublicFileManager');
                     $publicFileManager = new PublicFileManager();
                     $coverPagePath = $publicFileManager->getJournalFilesPath($journal->getId()) . '/';
                     $coverPagePath .= $coverFile;
                     $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($publicFileManager->readFile($coverPagePath)));
                     XMLCustomWriter::setAttribute($embedNode, 'filename', $article->getOriginalFileName($locale));
                     XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
                     XMLCustomWriter::setAttribute($embedNode, 'mime_type', String::mime_content_type($coverPagePath));
                 }
                 unset($coverNode);
             }
         }
     }
     XMLCustomWriter::createChildWithText($doc, $root, 'pages', $article->getPages(), false);
     // NOTE that this is a required field for import, but it's
     // possible here to generate nonconforming XML via export b/c
     // of the potentially missing date_published node. This is due
     // to legacy data issues WRT an earlier lack of ability to
     // define article pub dates. Some legacy data will be missing
     // this date.
     XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($article->getDatePublished()), false);
     if ($article->getAccessStatus() == ARTICLE_ACCESS_OPEN) {
         $accessNode =& XMLCustomWriter::createElement($doc, 'open_access');
         XMLCustomWriter::appendChild($root, $accessNode);
     }
     /* --- Permissions --- */
     $permissionsNode =& XMLCustomWriter::createElement($doc, 'permissions');
     XMLCustomWriter::appendChild($root, $permissionsNode);
     XMLCustomWriter::createChildWithText($doc, $permissionsNode, 'license_url', $article->getLicenseURL(), false);
     foreach ($article->getCopyrightHolder(null) as $locale => $copyrightHolder) {
         $copyrightHolderNode =& XMLCustomWriter::createChildWithText($doc, $permissionsNode, 'copyright_holder', $copyrightHolder, false);
         if ($copyrightHolderNode) {
             XMLCustomWriter::setAttribute($copyrightHolderNode, 'locale', $locale);
         }
         unset($copyrightHolderNode);
     }
     XMLCustomWriter::createChildWithText($doc, $permissionsNode, 'copyright_year', $article->getCopyrightYear(), false);
     /* --- */
     /* --- Galleys --- */
     foreach ($article->getGalleys() as $galley) {
         $galleyNode =& NativeExportDom::generateGalleyDom($doc, $journal, $issue, $article, $galley);
         if ($galleyNode !== null) {
             XMLCustomWriter::appendChild($root, $galleyNode);
         }
         unset($galleyNode);
     }
     /* --- Supplementary Files --- */
     foreach ($article->getSuppFiles() as $suppFile) {
         $suppNode =& NativeExportDom::generateSuppFileDom($doc, $journal, $issue, $article, $suppFile);
         if ($suppNode !== null) {
             XMLCustomWriter::appendChild($root, $suppNode);
         }
         unset($suppNode);
     }
     return $root;
 }
开发者ID:EreminDm,项目名称:water-cao,代码行数:101,代码来源:NativeExportDom.inc.php

示例9: addAttachment

 /**
  * Adds a file attachment to the email.
  * @param $filePath string complete path to the file to attach
  * @param $fileName string attachment file name (optional)
  * @param $contentType string attachment content type (optional)
  * @param $contentDisposition string attachment content disposition, inline or attachment (optional, default attachment)
  */
 function addAttachment($filePath, $fileName = '', $contentType = '', $contentDisposition = 'attachment')
 {
     if (($attachments =& $this->getData('attachments')) == null) {
         $attachments = array();
     }
     /* If the arguments $fileName and $contentType are not specified,
     			then try and determine them automatically. */
     if (empty($fileName)) {
         $fileName = basename($filePath);
     }
     if (empty($contentType)) {
         $contentType = String::mime_content_type($filePath);
         if (empty($contentType)) {
             $contentType = 'application/x-unknown-content-type';
         }
     }
     array_push($attachments, array('path' => $filePath, 'filename' => $fileName, 'content-type' => $contentType));
     return $this->setData('attachments', $attachments);
 }
开发者ID:doana,项目名称:pkp-lib,代码行数:26,代码来源:Mail.inc.php

示例10: downloadFile

 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $type string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $type = null, $inline = false)
 {
     if (is_readable($filePath)) {
         if ($type == null) {
             $type = String::mime_content_type($filePath);
             if (empty($type)) {
                 $type = 'application/octet-stream';
             }
         }
         header("Content-Type: {$type}");
         header("Content-Length: " . filesize($filePath));
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . basename($filePath) . "\"");
         header("Cache-Control: private");
         // Workarounds for IE weirdness
         header("Pragma: public");
         import('file.FileManager');
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
开发者ID:alenoosh,项目名称:ojs,代码行数:30,代码来源:FileManager.inc.php

示例11: foreach

 function &generateIssueDom(&$doc, &$journal, &$issue)
 {
     $root =& XMLCustomWriter::createElement($doc, 'issue');
     XMLCustomWriter::setAttribute($root, 'published', $issue->getPublished() ? 'true' : 'false');
     XMLCustomWriter::setAttribute($root, 'current', $issue->getCurrent() ? 'true' : 'false');
     XMLCustomWriter::setAttribute($root, 'public_id', $issue->getPublicIssueId(), false);
     if (is_array($issue->getTitle(null))) {
         foreach ($issue->getTitle(null) as $locale => $title) {
             $titleNode =& XMLCustomWriter::createChildWithText($doc, $root, 'title', $title, false);
             if ($titleNode) {
                 XMLCustomWriter::setAttribute($titleNode, 'locale', $locale);
             }
             unset($titleNode);
         }
     }
     if (is_array($issue->getDescription(null))) {
         foreach ($issue->getDescription(null) as $locale => $description) {
             $descriptionNode =& XMLCustomWriter::createChildWithText($doc, $root, 'description', $description, false);
             if ($descriptionNode) {
                 XMLCustomWriter::setAttribute($descriptionNode, 'locale', $locale);
             }
             unset($descriptionNode);
         }
     }
     XMLCustomWriter::createChildWithText($doc, $root, 'volume', $issue->getVolume(), false);
     XMLCustomWriter::createChildWithText($doc, $root, 'number', $issue->getNumber(), false);
     XMLCustomWriter::createChildWithText($doc, $root, 'year', $issue->getYear(), false);
     if (is_array($issue->getShowCoverPage(null))) {
         foreach (array_keys($issue->getShowCoverPage(null)) as $locale) {
             if ($issue->getShowCoverPage($locale)) {
                 $coverNode =& XMLCustomWriter::createElement($doc, 'cover');
                 XMLCustomWriter::appendChild($root, $coverNode);
                 XMLCustomWriter::setAttribute($coverNode, 'locale', $locale);
                 XMLCustomWriter::createChildWithText($doc, $coverNode, 'caption', $issue->getCoverPageDescription($locale), false);
                 $coverFile = $issue->getFileName($locale);
                 if ($coverFile != '') {
                     $imageNode =& XMLCustomWriter::createElement($doc, 'image');
                     XMLCustomWriter::appendChild($coverNode, $imageNode);
                     import('file.PublicFileManager');
                     $publicFileManager =& new PublicFileManager();
                     $coverPagePath = $publicFileManager->getJournalFilesPath($journal->getJournalId()) . '/';
                     $coverPagePath .= $coverFile;
                     $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($publicFileManager->readFile($coverPagePath)));
                     XMLCustomWriter::setAttribute($embedNode, 'filename', $issue->getOriginalFileName($locale));
                     XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
                     XMLCustomWriter::setAttribute($embedNode, 'mime_type', String::mime_content_type($coverPagePath));
                 }
                 unset($coverNode);
             }
         }
     }
     XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($issue->getDatePublished()), false);
     if (XMLCustomWriter::createChildWithText($doc, $root, 'access_date', NativeExportDom::formatDate($issue->getDatePublished()), false) == null) {
         // This may be an open access issue. Check and flag
         // as necessary.
         if ($issue->getAccessStatus() == OPEN_ACCESS || !$journal->getSetting('enableSubscriptions') && $issue->getAccessStatus() == ISSUE_DEFAULT) {
             $accessNode =& XMLCustomWriter::createElement($doc, 'open_access');
             XMLCustomWriter::appendChild($root, $accessNode);
         }
     }
     $sectionDao =& DAORegistry::getDAO('SectionDAO');
     foreach ($sectionDao->getSectionsForIssue($issue->getIssueId()) as $section) {
         $sectionNode =& NativeExportDom::generateSectionDom($doc, $journal, $issue, $section);
         XMLCustomWriter::appendChild($root, $sectionNode);
         unset($sectionNode);
     }
     return $root;
 }
开发者ID:Jouper,项目名称:jouper,代码行数:68,代码来源:NativeExportDom.inc.php

示例12: downloadFile

 /**
  * Download a file.
  * Outputs HTTP headers and file content for download
  * @param $filePath string the location of the file to be sent
  * @param $type string the MIME type of the file, optional
  * @param $inline print file as inline instead of attachment, optional
  * @return boolean
  */
 function downloadFile($filePath, $type = null, $inline = false, $filename = null)
 {
     if (is_null($filename)) {
         $filename = basename($filePath);
     }
     $u_agent = $_SERVER['HTTP_USER_AGENT'];
     if (preg_match('/MSIE/i', $u_agent) && !preg_match('/Opera/i', $u_agent) || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false) {
         $filename = iconv('utf8', 'big5', $filename);
     }
     //$filename = basename($filePath);
     $result = null;
     if (HookRegistry::call('FileManager::downloadFile', array(&$filePath, &$type, &$inline, &$result))) {
         return $result;
     }
     if (is_readable($filePath)) {
         if ($type == null) {
             $type = String::mime_content_type($filePath);
             if (empty($type)) {
                 $type = 'application/octet-stream';
             }
         }
         Registry::clear();
         // Free some memory
         header("Content-Type: {$type}");
         header("Content-Length: " . filesize($filePath));
         header("Content-Disposition: " . ($inline ? 'inline' : 'attachment') . "; filename=\"" . $filename . "\"");
         header("Cache-Control: private");
         // Workarounds for IE weirdness
         header("Pragma: public");
         import('file.FileManager');
         FileManager::readFile($filePath, true);
         return true;
     } else {
         return false;
     }
 }
开发者ID:pulipulichen,项目名称:ocs,代码行数:44,代码来源:FileManager.inc.php

示例13: foreach


//.........这里部分代码省略.........
             }
             unset($subjectClassNode);
         }
     }
     $coverageNode =& XMLCustomWriter::createElement($doc, 'coverage');
     $isCoverageNecessary = false;
     if (is_array($article->getCoverageGeo(null))) {
         foreach ($article->getCoverageGeo(null) as $locale => $geographical) {
             $geographicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'geographical', $geographical, false);
             if ($geographicalNode) {
                 XMLCustomWriter::setAttribute($geographicalNode, 'locale', $locale);
                 $isCoverageNecessary = true;
             }
             unset($geographicalNode);
         }
     }
     if (is_array($article->getCoverageChron(null))) {
         foreach ($article->getCoverageChron(null) as $locale => $chronological) {
             $chronologicalNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'chronological', $chronological, false);
             if ($chronologicalNode) {
                 XMLCustomWriter::setAttribute($chronologicalNode, 'locale', $locale);
                 $isCoverageNecessary = true;
             }
             unset($chronologicalNode);
         }
     }
     if (is_array($article->getCoverageSample(null))) {
         foreach ($article->getCoverageSample(null) as $locale => $sample) {
             $sampleNode =& XMLCustomWriter::createChildWithText($doc, $coverageNode, 'sample', $sample, false);
             if ($sampleNode) {
                 XMLCustomWriter::setAttribute($sampleNode, 'locale', $locale);
                 $isCoverageNecessary = true;
             }
             unset($sampleNode);
         }
     }
     if ($isCoverageNecessary) {
         XMLCustomWriter::appendChild($indexingNode, $coverageNode);
         $isIndexingNecessary = true;
     }
     if ($isIndexingNecessary) {
         XMLCustomWriter::appendChild($root, $indexingNode);
     }
     /* --- */
     /* --- Authors --- */
     foreach ($article->getAuthors() as $author) {
         $authorNode =& NativeExportDom::generateAuthorDom($doc, $journal, $issue, $article, $author);
         XMLCustomWriter::appendChild($root, $authorNode);
         unset($authorNode);
     }
     /* --- */
     if (is_array($article->getShowCoverPage(null))) {
         foreach (array_keys($article->getShowCoverPage(null)) as $locale) {
             if ($article->getShowCoverPage($locale)) {
                 $coverNode =& XMLCustomWriter::createElement($doc, 'cover');
                 XMLCustomWriter::appendChild($root, $coverNode);
                 XMLCustomWriter::setAttribute($coverNode, 'locale', $locale);
                 XMLCustomWriter::createChildWithText($doc, $coverNode, 'altText', $issue->getCoverPageDescription($locale), false);
                 $coverFile = $article->getFileName($locale);
                 if ($coverFile != '') {
                     $imageNode =& XMLCustomWriter::createElement($doc, 'image');
                     XMLCustomWriter::appendChild($coverNode, $imageNode);
                     import('classes.file.PublicFileManager');
                     $publicFileManager = new PublicFileManager();
                     $coverPagePath = $publicFileManager->getJournalFilesPath($journal->getId()) . '/';
                     $coverPagePath .= $coverFile;
                     $embedNode =& XMLCustomWriter::createChildWithText($doc, $imageNode, 'embed', base64_encode($publicFileManager->readFile($coverPagePath)));
                     XMLCustomWriter::setAttribute($embedNode, 'filename', $article->getOriginalFileName($locale));
                     XMLCustomWriter::setAttribute($embedNode, 'encoding', 'base64');
                     XMLCustomWriter::setAttribute($embedNode, 'mime_type', String::mime_content_type($coverPagePath));
                 }
                 unset($coverNode);
             }
         }
     }
     XMLCustomWriter::createChildWithText($doc, $root, 'pages', $article->getPages(), false);
     XMLCustomWriter::createChildWithText($doc, $root, 'date_published', NativeExportDom::formatDate($article->getDatePublished()), false);
     if ($article->getAccessStatus() == ARTICLE_ACCESS_OPEN) {
         $accessNode =& XMLCustomWriter::createElement($doc, 'open_access');
         XMLCustomWriter::appendChild($root, $accessNode);
     }
     /* --- */
     /* --- Galleys --- */
     foreach ($article->getGalleys() as $galley) {
         $galleyNode =& NativeExportDom::generateGalleyDom($doc, $journal, $issue, $article, $galley);
         if ($galleyNode !== null) {
             XMLCustomWriter::appendChild($root, $galleyNode);
         }
         unset($galleyNode);
     }
     /* --- Supplementary Files --- */
     foreach ($article->getSuppFiles() as $suppFile) {
         $suppNode =& NativeExportDom::generateSuppFileDom($doc, $journal, $issue, $article, $suppFile);
         if ($suppNode !== null) {
             XMLCustomWriter::appendChild($root, $suppNode);
         }
         unset($suppNode);
     }
     return $root;
 }
开发者ID:JovanyJeff,项目名称:hrp,代码行数:101,代码来源:NativeExportDom.inc.php

示例14: uploadImg

function uploadImg($clib, $chkT, $selR)
{
    global $cfg;
    global $l;
    if (!$cfg['upload']) {
        return false;
    }
    foreach ($_FILES['nfile']['size'] as $key => $size) {
        if ($size > 0) {
            // get file extension and check for validity
            $ext = pathinfo($_FILES['nfile']['name'][$key]);
            $mimeType = String::mime_content_type($_FILES['nfile']['tmp_name'][0]);
            $ext = strtolower($ext['extension']);
            if (!in_array($ext, $cfg['valid'])) {
                // invalid image (only checks extension)
                echo $l->m('er_029');
                return false;
            }
            if (!in_array($mimeType, $cfg['mimeTypes'])) {
                // invalid image (checks mime type)
                echo $l->m('er_029');
                return false;
            }
            $path = str_replace('//', '/', $cfg['root_dir'] . $clib);
            // remove double slash in path
            $nfile = fixFileName($_FILES['nfile']['name'][$key]);
            // remove invalid characters in filename
            // Check that the user doesn't exceed their upload limit:
            $newSize = dirsize($path) + $_FILES['nfile']['size'][$key];
            if ($newSize > $cfg['ulLimit'] && $cfg['ulLimit'] != 0) {
                echo 'Warning: Upload limit exceeded';
                return false;
            }
            // move file to temp directory for processing
            if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $path . '/' . $nfile)) {
                // upload image to temp dir
                echo $l->m('er_028');
                return false;
            }
            $size = getimagesize($path . '/' . $nfile);
            // process (thumbnail) images
            $arr = $cfg['thumbs'];
            foreach ($arr as $key => $thumb) {
                if (in_array($key, $chkT)) {
                    // create new phpThumb() object
                    require_once dirname(__FILE__) . '/phpThumb/ThumbLib.inc.php';
                    $phpThumb = PhpThumbFactory::create($path . '/' . $nfile);
                    // Create object
                    //-------------------------------------------------------------------------
                    if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) {
                        // size value is set -> RESIZING and source image is larger than preset sizes
                        // resize parameters
                        $phpThumb->resize($thumb['size'], $thumb['size']);
                        // create file suffix
                        if ($thumb['ext'] == '*') {
                            // image size is used
                            $dim = '_' . $thumb['size'];
                            // e.g. _1280
                        } else {
                            if ($thumb['ext'] == '') {
                                // no suffix is created
                                $dim = '';
                            } else {
                                // suffix is set to $thumb['ext']
                                $dim = '_' . $thumb['ext'];
                            }
                        }
                        //-------------------------------------------------------------------------
                    } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') {
                        // size value is set to '0' -> NO RESIZING
                        // create file suffix
                        if ($thumb['ext'] == '*') {
                            // image size is used
                            $dim = '_' . ($size[0] <= $size[1] ? $size[1] : $size[0]);
                            // source height or width - e.g. _1280
                        } else {
                            if ($thumb['ext'] == '') {
                                // no suffix is created
                                $dim = '';
                            } else {
                                // suffix is set to $thumb['ext']
                                $dim = '_' . $thumb['ext'];
                            }
                        }
                        //-------------------------------------------------------------------------
                    } else {
                        // default setting - images smaller than predefined sizes
                        $dim = '';
                        // no file suffix is used
                    }
                    //-------------------------------------------------------------------------
                    $nthumb = fixFileName(basename($nfile, '.' . $ext) . sanitize_filename($dim) . '.' . $ext);
                    $nthumb = chkFileName($path, $nthumb);
                    // rename if file already exists
                    $phpThumb->save($path . $nthumb);
                    @chmod($path . $nthumb, 0755) or die($l->m('er_028'));
                    unset($phpThumb);
                }
            }
            @unlink($path . '/' . $nfile);
//.........这里部分代码省略.........
开发者ID:JovanyJeff,项目名称:hrp,代码行数:101,代码来源:rfiles.php

示例15: uploadImg

function uploadImg($clib, $chkT, $selR)
{
    global $cfg;
    global $l;
    if (!$cfg['upload']) {
        return false;
    }
    foreach ($_FILES['nfile']['size'] as $key => $size) {
        if ($size > 0) {
            // get file extension and check for validity
            $ext = pathinfo($_FILES['nfile']['name'][$key]);
            $mimeType = String::mime_content_type($_FILES['nfile']['tmp_name'][0]);
            $ext = strtolower($ext['extension']);
            if (!in_array($ext, $cfg['valid'])) {
                // invalid image (only checks extension)
                echo $l->m('er_029');
                return false;
            }
            if (!in_array($mimeType, $cfg['mimeTypes'])) {
                // invalid image (checks mime type)
                echo $l->m('er_029');
                return false;
            }
            $path = str_replace('//', '/', $cfg['root_dir'] . $clib);
            // remove double slash in path
            $nfile = fixFileName($_FILES['nfile']['name'][$key]);
            // remove invalid characters in filename
            // Check that the user doesn't exceed their upload limit:
            $newSize = dirsize($path) + $_FILES['nfile']['size'][$key];
            if ($newSize > $cfg['ulLimit'] && $cfg['ulLimit'] != 0) {
                echo 'Warning: Upload limit exceeded';
                return false;
            }
            // move file to temp directory for processing
            if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $path . '/' . $nfile)) {
                // upload image to temp dir
                echo $l->m('er_028');
                return false;
            }
            $size = getimagesize($path . '/' . $nfile);
            // process (thumbnail) images
            $arr = $cfg['thumbs'];
            foreach ($arr as $key => $thumb) {
                if (in_array($key, $chkT)) {
                    // create new phpThumb() object
                    require_once dirname(__FILE__) . '/phpThumb/phpthumb.class.php';
                    $phpThumb = new phpThumb();
                    // create object
                    // parameters
                    $phpThumb->config_cache_disable_warning = true;
                    // disable cache warning
                    $phpThumb->config_output_format = $ext;
                    // output format
                    $phpThumb->src = $path . '/' . $nfile;
                    // destination
                    $phpThumb->q = 95;
                    // compression level for jpeg
                    if ($selR != '') {
                        // set auto rotate
                        $phpThumb->ar = $selR;
                    }
                    //-------------------------------------------------------------------------
                    if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) {
                        // size value is set -> RESIZING and source image is larger than preset sizes
                        // resize parameters
                        if ($size[0] < $size[1]) {
                            // portrait
                            $phpThumb->h = $thumb['size'];
                            // max. height
                        } else {
                            $phpThumb->w = $thumb['size'];
                            // max. width
                        }
                        // crop parameters
                        if ($thumb['crop'] == true) {
                            $phpThumb->zc = 1;
                            // set zoom crop
                            $phpThumb->w = $thumb['size'];
                            // width
                            $phpThumb->h = $thumb['size'];
                            // height
                        }
                        // create file suffix
                        if ($thumb['ext'] == '*') {
                            // image size is used
                            $dim = '_' . $thumb['size'];
                            // e.g. _1280
                        } else {
                            if ($thumb['ext'] == '') {
                                // no suffix is created
                                $dim = '';
                            } else {
                                // suffix is set to $thumb['ext']
                                $dim = '_' . $thumb['ext'];
                            }
                        }
                        //-------------------------------------------------------------------------
                    } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') {
                        // size value is set to '0' -> NO RESIZING
                        // crop parameters
//.........这里部分代码省略.........
开发者ID:anorton,项目名称:pkp-lib,代码行数:101,代码来源:rfiles.php


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