本文整理汇总了PHP中CKFinder_Connector_Utils_FileSystem::sendFile方法的典型用法代码示例。如果您正苦于以下问题:PHP CKFinder_Connector_Utils_FileSystem::sendFile方法的具体用法?PHP CKFinder_Connector_Utils_FileSystem::sendFile怎么用?PHP CKFinder_Connector_Utils_FileSystem::sendFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CKFinder_Connector_Utils_FileSystem
的用法示例。
在下文中一共展示了CKFinder_Connector_Utils_FileSystem::sendFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendResponse
/**
* send response (file)
* @access public
*
*/
public function sendResponse()
{
if (!function_exists('ob_list_handlers') || ob_list_handlers()) {
@ob_end_clean();
}
header("Content-Encoding: none");
$this->checkConnector();
$this->checkRequest();
if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
}
$fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($_GET["FileName"]);
$_resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
if (!$_resourceTypeInfo->checkExtension($fileName, false)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
$filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $fileName);
if ($_resourceTypeInfo->checkIsHiddenFile($fileName) || !file_exists($filePath) || !is_file($filePath)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND);
}
$fileName = CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($fileName);
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Expires: 0");
if (!empty($_GET['format']) && $_GET['format'] == 'text') {
header("Content-Type: text/plain; charset=utf-8");
} else {
$user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
$encodedName = str_replace("\"", "\\\"", $fileName);
if (strpos($user_agent, "MSIE") !== false) {
$encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName));
}
header("Content-type: application/octet-stream; name=\"" . $fileName . "\"");
header("Content-Disposition: attachment; filename=\"" . $encodedName . "\"");
}
header("Content-Length: " . filesize($filePath));
CKFinder_Connector_Utils_FileSystem::sendFile($filePath);
exit;
}
示例2: sendZipFile
/**
* Sends generated zip file to the user
*/
protected function sendZipFile()
{
if (!function_exists('ob_list_handlers') || ob_list_handlers()) {
@ob_end_clean();
}
header("Content-Encoding: none");
$this->checkConnector();
$this->checkRequest();
// empty wystarczy
if (empty($_GET['FileName'])) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND);
}
$resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
$hash = $resourceTypeInfo->getHash();
if ($hash !== $_GET['hash'] || $hash !== substr($_GET['FileName'], 16, 16)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_VIEW)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
}
$fileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['FileName']));
if (!CKFinder_Connector_Utils_FileSystem::checkFileName($fileName)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
if (strtolower(pathinfo($fileName, PATHINFO_EXTENSION)) !== 'zip') {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
}
$dest_dir = CKFinder_Connector_Utils_FileSystem::getTmpDir();
$filePath = CKFinder_Connector_Utils_FileSystem::combinePaths($dest_dir, $fileName);
if (!file_exists($filePath) || !is_file($filePath)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND);
}
if (!is_readable($filePath)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
}
$zipFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(trim($_GET['ZipName']));
if (!CKFinder_Connector_Utils_FileSystem::checkFileName($zipFileName)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
}
$fileFilename = pathinfo($zipFileName, PATHINFO_BASENAME);
header("Content-Encoding: none");
header("Cache-Control: cache, must-revalidate");
header("Pragma: public");
header("Expires: 0");
$user_agent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
$encodedName = str_replace("\"", "\\\"", $fileFilename);
if (strpos($user_agent, "MSIE") !== false) {
$encodedName = str_replace(array("+", "%2E"), array(" ", "."), urlencode($encodedName));
}
header("Content-type: application/octet-stream; name=\"" . $fileFilename . "\"");
header("Content-Disposition: attachment; filename=\"" . $encodedName . "\"");
header("Content-Length: " . filesize($filePath));
CKFinder_Connector_Utils_FileSystem::sendFile($filePath);
exit;
}