本文整理汇总了PHP中OC\Files\Filesystem::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getMimeType方法的具体用法?PHP Filesystem::getMimeType怎么用?PHP Filesystem::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::getMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendHeaders
/**
* @param string $filename
* @param string $name
*/
private static function sendHeaders($filename, $name)
{
OC_Response::setContentDispositionHeader($name, 'attachment');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
$filesize = \OC\Files\Filesystem::filesize($filename);
header('Content-Type: ' . \OC_Helper::getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename)));
if ($filesize > -1) {
OC_Response::setContentLengthHeader($filesize);
}
}
示例2: scanFile
/**
* scan a file for music
*
* @param string $path
* @return boolean
*/
public function scanFile($path)
{
$mimeType = \OC\Files\Filesystem::getMimeType($path);
if ($mimeType === 'application/ogg' or substr($mimeType, 0, 5) === 'audio') {
$track = new Track($path);
$data = $track->getTags();
if (!empty($data)) {
$artistId = $this->collection->addArtist($data['artist']);
$albumId = $this->collection->addAlbum($data['album'], $artistId);
$this->collection->addSong($data['title'], $path, $artistId, $albumId, $data['length'], $data['track'], $data['size']);
}
}
return true;
}
示例3: sendHeaders
/**
* @param string $filename
* @param string $name
* @param boolean $isAttachment ; enforce download of file
*/
private static function sendHeaders($filename, $name, $isAttachment = true)
{
if ($isAttachment) {
OC_Response::setContentDispositionHeader($name, 'attachment');
}
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
$fileSize = \OC\Files\Filesystem::filesize($filename);
$type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
header('Content-Type: ' . $type);
if ($fileSize > -1) {
OC_Response::setContentLengthHeader($fileSize);
}
}
示例4: sendHeaders
/**
* @param string $filename
* @param string $name
* @param bool $zip
*/
private static function sendHeaders($filename, $name, $zip = false)
{
OC_Response::setContentDispositionHeader($name, 'attachment');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
if ($zip) {
header('Content-Type: application/zip');
} else {
$filesize = \OC\Files\Filesystem::filesize($filename);
header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
if ($filesize > -1) {
header("Content-Length: " . $filesize);
}
}
}
示例5: showShare
/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $token
* @param string $path
* @return TemplateResponse|RedirectResponse
*/
public function showShare($token, $path = '')
{
\OC_User::setIncognitoMode(true);
// Check whether share exists
$linkItem = Share::getShareByToken($token, false);
if ($linkItem === false) {
return new NotFoundResponse();
}
$shareOwner = $linkItem['uid_owner'];
$originalSharePath = $this->getPath($token);
// Share is password protected - check whether the user is permitted to access the share
if (isset($linkItem['share_with']) && !Helper::authenticate($linkItem)) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', array('token' => $token)));
}
if (Filesystem::isReadable($originalSharePath . $path)) {
$getPath = Filesystem::normalizePath($path);
$originalSharePath .= $path;
} else {
throw new OCP\Files\NotFoundException();
}
$file = basename($originalSharePath);
$shareTmpl = [];
$shareTmpl['displayName'] = User::getDisplayName($shareOwner);
$shareTmpl['filename'] = $file;
$shareTmpl['directory_path'] = $linkItem['file_target'];
$shareTmpl['mimetype'] = Filesystem::getMimeType($originalSharePath);
$shareTmpl['previewSupported'] = \OC::$server->getPreviewManager()->isMimeSupported($shareTmpl['mimetype']);
$shareTmpl['dirToken'] = $linkItem['token'];
$shareTmpl['sharingToken'] = $token;
$shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
$shareTmpl['protected'] = isset($linkItem['share_with']) ? 'true' : 'false';
$shareTmpl['dir'] = '';
$nonHumanFileSize = \OC\Files\Filesystem::filesize($originalSharePath);
$shareTmpl['nonHumanFileSize'] = $nonHumanFileSize;
$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($nonHumanFileSize);
// Show file list
if (Filesystem::is_dir($originalSharePath)) {
$shareTmpl['dir'] = $getPath;
$maxUploadFilesize = Util::maxUploadFilesize($originalSharePath);
$freeSpace = Util::freeSpace($originalSharePath);
$uploadLimit = Util::uploadLimit();
$folder = new Template('files', 'list', '');
$folder->assign('dir', $getPath);
$folder->assign('dirToken', $linkItem['token']);
$folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
$folder->assign('isPublic', true);
$folder->assign('publicUploadEnabled', 'no');
$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
$folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
$folder->assign('freeSpace', $freeSpace);
$folder->assign('uploadLimit', $uploadLimit);
// PHP upload limit
$folder->assign('usedSpacePercent', 0);
$folder->assign('trash', false);
$shareTmpl['folder'] = $folder->fetchPage();
}
$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
$csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
$csp->addAllowedFrameDomain('\'self\'');
$response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
$response->setContentSecurityPolicy($csp);
return $response;
}
示例6: getContentType
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*
* @return mixed
*/
public function getContentType()
{
if (isset($this->fileinfo_cache['mimetype'])) {
$mimeType = $this->fileinfo_cache['mimetype'];
} else {
$mimeType = \OC\Files\Filesystem::getMimeType($this->path);
}
return \OC_Helper::getSecureMimeType($mimeType);
}
示例7: getContentType
/**
* Returns the mime-type for a file
*
* If null is returned, we'll assume application/octet-stream
*
* @return mixed
*/
public function getContentType()
{
if (isset($this->fileinfo_cache['mimetype'])) {
return $this->fileinfo_cache['mimetype'];
}
return \OC\Files\Filesystem::getMimeType($this->path);
}
示例8: File
<?php
/**
* ownCloud - Documents App
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Documents;
\OCP\JSON::checkLoggedIn();
$path = Helper::getArrayValueByKey($_GET, 'path');
if (!empty($path)) {
if (\OC\Files\Filesystem::getMimeType($path) !== Filter_Office::NATIVE_MIMETYPE) {
$fileInfo = \OC\Files\Filesystem::getFileInfo($path);
$file = new File($fileInfo->getId());
$genesis = new Genesis($file);
$fullPath = $genesis->getPath();
} else {
$fullPath = '/files' . $path;
}
$download = new Download(\OCP\User::getUser(), $fullPath);
$download->sendResponse();
}
exit;
示例9: isset
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Init owncloud
// Check if we are a user
OCP\JSON::checkLoggedIn();
// Set the session key for the file we are about to edit.
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$filename = isset($_GET['file']) ? $_GET['file'] : '';
if (!empty($filename)) {
$path = $dir . '/' . $filename;
$writeable = \OC\Files\Filesystem::isUpdatable($path);
$mime = \OC\Files\Filesystem::getMimeType($path);
$mtime = \OC\Files\Filesystem::filemtime($path);
$filecontents = \OC\Files\Filesystem::file_get_contents($path);
$encoding = mb_detect_encoding($filecontents . "a", "UTF-8, WINDOWS-1252, ISO-8859-15, ISO-8859-1, ASCII", true);
if ($encoding == "") {
// set default encoding if it couldn't be detected
$encoding = 'ISO-8859-15';
}
$filecontents = iconv($encoding, "UTF-8", $filecontents);
OCP\JSON::success(array('data' => array('filecontents' => $filecontents, 'writeable' => $writeable, 'mime' => $mime, 'mtime' => $mtime)));
} else {
OCP\JSON::error(array('data' => array('message' => 'Invalid file path supplied.')));
}
示例10: get
/**
* return the content of a file or return a zip file containing multiple files
*
* @param string $dir
* @param string $file ; separated list of files to download
* @param boolean $only_header ; boolean to only send header of the request
*/
public static function get($dir, $files, $only_header = false)
{
$xsendfile = false;
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
$xsendfile = true;
}
if (is_array($files) && count($files) == 1) {
$files = $files[0];
}
if (is_array($files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
$l = OC_L10N::get('lib');
throw new Exception($l->t('cannot open "%s"', array($filename)));
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (\OC\Files\Filesystem::is_file($file)) {
$tmpFile = \OC\Files\Filesystem::toTmpFile($file);
self::$tmpFiles[] = $tmpFile;
$zip->addFile($tmpFile, basename($file));
} elseif (\OC\Files\Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
$zip->close();
if ($xsendfile) {
$filename = OC_Helper::moveToNoClean($filename);
}
$basename = basename($dir);
if ($basename) {
$name = $basename . '.zip';
} else {
$name = 'download.zip';
}
set_time_limit($executionTime);
} elseif (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
$filename = OC_Helper::tmpFile('.zip');
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
$l = OC_L10N::get('lib');
throw new Exception($l->t('cannot open "%s"', array($filename)));
}
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
$zip->close();
if ($xsendfile) {
$filename = OC_Helper::moveToNoClean($filename);
}
$name = $files . '.zip';
set_time_limit($executionTime);
} else {
$zip = false;
$filename = $dir . '/' . $files;
$name = $files;
if ($xsendfile && OC_App::isEnabled('files_encryption')) {
$xsendfile = false;
}
}
OC_Util::obEnd();
if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
OC_Response::setContentDispositionHeader($name, 'attachment');
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
if ($zip) {
ini_set('zlib.output_compression', 'off');
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
self::addSendfileHeader($filename);
} else {
$filesize = \OC\Files\Filesystem::filesize($filename);
header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
if ($filesize > -1) {
header("Content-Length: " . $filesize);
}
if ($xsendfile) {
list($storage) = \OC\Files\Filesystem::resolvePath(\OC\Files\Filesystem::getView()->getAbsolutePath($filename));
/**
* @var \OC\Files\Storage\Storage $storage
*/
if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Local')) {
self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
}
}
}
} elseif ($zip or !\OC\Files\Filesystem::file_exists($filename)) {
//.........这里部分代码省略.........
示例11: getSingleFile
/**
* @param View $view
* @param string $name
* @param string $dir
* @param array $params ; 'head' boolean to only send header of the request ; 'range' http range header
*/
private static function getSingleFile($view, $dir, $name, $params)
{
$filename = $dir . '/' . $name;
OC_Util::obEnd();
$view->lockFile($filename, ILockingProvider::LOCK_SHARED);
$rangeArray = array();
if (isset($params['range']) && substr($params['range'], 0, 6) === 'bytes=') {
$rangeArray = self::parseHttpRangeHeader(substr($params['range'], 6), \OC\Files\Filesystem::filesize($filename));
}
if (\OC\Files\Filesystem::isReadable($filename)) {
self::sendHeaders($filename, $name, $rangeArray);
} elseif (!\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->printPage();
exit;
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
}
if (isset($params['head']) && $params['head']) {
return;
}
if (!empty($rangeArray)) {
try {
if (count($rangeArray) == 1) {
$view->readfilePart($filename, $rangeArray[0]['from'], $rangeArray[0]['to']);
} else {
// check if file is seekable (if not throw UnseekableException)
// we have to check it before body contents
$view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']);
$type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
foreach ($rangeArray as $range) {
echo "\r\n--" . self::getBoundary() . "\r\n" . "Content-type: " . $type . "\r\n" . "Content-range: bytes " . $range['from'] . "-" . $range['to'] . "/" . $range['size'] . "\r\n\r\n";
$view->readfilePart($filename, $range['from'], $range['to']);
}
echo "\r\n--" . self::getBoundary() . "--\r\n";
}
} catch (\OCP\Files\UnseekableException $ex) {
// file is unseekable
header_remove('Accept-Ranges');
header_remove('Content-Range');
header("HTTP/1.1 200 OK");
self::sendHeaders($filename, $name, array());
$view->readfile($filename);
}
} else {
$view->readfile($filename);
}
}
示例12: header
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->assign('file', $filename);
$tmpl->printPage();
exit;
}
$ftype = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader(\OC\Files\Filesystem::filesize($filename));
OC_Util::obEnd();
\OC\Files\Filesystem::readfile($filename);
示例13: header
<?php
// Check if we are a user
OCP\User::checkLoggedIn();
$filename = $_GET["file"];
if (!\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->assign('file', $filename);
$tmpl->printPage();
exit;
}
$ftype = \OC_Helper::getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
header('Content-Type:' . $ftype);
OCP\Response::setContentDispositionHeader(basename($filename), 'attachment');
OCP\Response::disableCaching();
OCP\Response::setContentLengthHeader(\OC\Files\Filesystem::filesize($filename));
OC_Util::obEnd();
\OC\Files\Filesystem::readfile($filename);
示例14: get
/**
* return the content of a file or return a zip file containing multiple files
*
* @param string $dir
* @param string $file ; separated list of files to download
* @param boolean $only_header ; boolean to only send header of the request
*/
public static function get($dir, $files, $only_header = false)
{
$xsendfile = false;
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
$xsendfile = true;
}
if (is_array($files) && count($files) == 1) {
$files = $files[0];
}
if (is_array($files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
if ($xsendfile) {
$filename = OC_Helper::tmpFileNoClean('.zip');
} else {
$filename = OC_Helper::tmpFile('.zip');
}
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
exit("cannot open <{$filename}>\n");
}
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (\OC\Files\Filesystem::is_file($file)) {
$tmpFile = \OC\Files\Filesystem::toTmpFile($file);
self::$tmpFiles[] = $tmpFile;
$zip->addFile($tmpFile, basename($file));
} elseif (\OC\Files\Filesystem::is_dir($file)) {
self::zipAddDir($file, $zip);
}
}
$zip->close();
$basename = basename($dir);
if ($basename) {
$name = $basename . '.zip';
} else {
$name = 'owncloud.zip';
}
set_time_limit($executionTime);
} elseif (\OC\Files\Filesystem::is_dir($dir . '/' . $files)) {
self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
if ($xsendfile) {
$filename = OC_Helper::tmpFileNoClean('.zip');
} else {
$filename = OC_Helper::tmpFile('.zip');
}
if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) {
exit("cannot open <{$filename}>\n");
}
$file = $dir . '/' . $files;
self::zipAddDir($file, $zip);
$zip->close();
$name = $files . '.zip';
set_time_limit($executionTime);
} else {
$zip = false;
$filename = $dir . '/' . $files;
$name = $files;
}
OC_Util::obEnd();
if ($zip or \OC\Files\Filesystem::isReadable($filename)) {
if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
header('Content-Disposition: attachment; filename="' . rawurlencode($name) . '"');
} else {
header('Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($name) . '; filename="' . rawurlencode($name) . '"');
}
header('Content-Transfer-Encoding: binary');
OC_Response::disableCaching();
if ($zip) {
ini_set('zlib.output_compression', 'off');
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($filename));
self::addSendfileHeader($filename);
} else {
header('Content-Type: ' . \OC\Files\Filesystem::getMimeType($filename));
header("Content-Length: " . \OC\Files\Filesystem::filesize($filename));
list($storage) = \OC\Files\Filesystem::resolvePath($filename);
if ($storage instanceof \OC\Files\Storage\Local) {
self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
}
}
} elseif ($zip or !\OC\Files\Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template('', '404', 'guest');
$tmpl->assign('file', $name);
$tmpl->printPage();
} else {
header("HTTP/1.0 403 Forbidden");
die('403 Forbidden');
//.........这里部分代码省略.........
示例15: catch
//400 Bad Request
\OC_Response::setStatus(400);
\OC_Log::write('core-preview', 'No file parameter was passed', \OC_Log::DEBUG);
exit;
}
if ($maxX === 0 || $maxY === 0) {
//400 Bad Request
\OC_Response::setStatus(400);
\OC_Log::write('core-preview', 'x and/or y set to 0', \OC_Log::DEBUG);
exit;
}
try {
$preview = new \OC\Preview(\OC_User::getUser(), 'files');
if (!$always and !$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) {
\OC_Response::setStatus(404);
} else {
$preview->setFile($file);
$preview->setMaxX($maxX);
$preview->setMaxY($maxY);
$preview->setScalingUp($scalingUp);
$preview->setKeepAspect($keepAspect);
}
$preview->showPreview();
} catch (\Exception $e) {
\OC_Response::setStatus(500);
\OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG);
}