本文整理汇总了PHP中CKSource\CKFinder\Filesystem\Path::combine方法的典型用法代码示例。如果您正苦于以下问题:PHP Path::combine方法的具体用法?PHP Path::combine怎么用?PHP Path::combine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CKSource\CKFinder\Filesystem\Path
的用法示例。
在下文中一共展示了Path::combine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(Request $request, WorkingFolder $workingFolder, Config $config, CacheManager $cache)
{
$fileName = (string) $request->get('fileName');
if (null === $fileName || !File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException('Invalid file name');
}
if (!Image::isSupportedExtension(pathinfo($fileName, PATHINFO_EXTENSION))) {
throw new InvalidNameException('Invalid source file name');
}
if (!$workingFolder->containsFile($fileName)) {
throw new FileNotFoundException();
}
$cachePath = Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName);
$imageInfo = array();
$cachedInfo = $cache->get($cachePath);
if ($cachedInfo && isset($cachedInfo['width']) && isset($cachedInfo['height'])) {
$imageInfo = $cachedInfo;
} else {
$file = new DownloadedFile($fileName, $this->app);
if ($file->isValid()) {
$image = Image::create($file->getContents());
$imageInfo = $image->getInfo();
$cache->set($cachePath, $imageInfo);
}
}
return $imageInfo;
}
示例2: execute
public function execute(Request $request, WorkingFolder $workingFolder, EventDispatcher $dispatcher, CacheManager $cache, ResizedImageRepository $resizedImageRepository, ThumbnailRepository $thumbnailRepository, Acl $acl)
{
$fileName = (string) $request->query->get('fileName');
$editedImage = new EditedImage($fileName, $this->app);
$saveAsNew = false;
if (!$editedImage->exists()) {
$saveAsNew = true;
$editedImage->saveAsNew(true);
} else {
// If file exists check for FILE_DELETE permission
$resourceTypeName = $workingFolder->getResourceType()->getName();
$path = $workingFolder->getClientCurrentFolder();
if (!$acl->isAllowed($resourceTypeName, $path, Permission::FILE_DELETE)) {
throw new UnauthorizedException(sprintf('Unauthorized: no FILE_DELETE permission in %s:%s', $resourceTypeName, $path));
}
}
if (!Image::isSupportedExtension($editedImage->getExtension())) {
throw new InvalidExtensionException('Unsupported image type or not image file');
}
$imageFormat = Image::mimeTypeFromExtension($editedImage->getExtension());
$uploadedData = (string) $request->request->get('content');
if (null === $uploadedData || strpos($uploadedData, 'data:image/png;base64,') !== 0) {
throw new InvalidUploadException('Invalid upload. Expected base64 encoded PNG image.');
}
$data = explode(',', $uploadedData);
$data = isset($data[1]) ? base64_decode($data[1]) : false;
if (!$data) {
throw new InvalidUploadException();
}
try {
$uploadedImage = Image::create($data);
} catch (\Exception $e) {
// No need to check if secureImageUploads is enabled - image must be valid here
throw new InvalidUploadException('Invalid upload: corrupted image', Error::UPLOADED_CORRUPT, array(), $e);
}
$editedImage->setNewContents($uploadedImage->getData($imageFormat));
$editedImage->setNewDimensions($uploadedImage->getWidth(), $uploadedImage->getHeight());
if (!$editedImage->isValid()) {
throw new InvalidUploadException('Invalid file provided');
}
$editFileEvent = new EditFileEvent($this->app, $editedImage);
$imageInfo = $uploadedImage->getInfo();
$cache->set(Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName), $uploadedImage->getInfo());
$dispatcher->dispatch(CKFinderEvent::SAVE_IMAGE, $editFileEvent);
$saved = false;
if (!$editFileEvent->isPropagationStopped()) {
$saved = $editedImage->save($editFileEvent->getNewContents());
if (!$saved) {
throw new AccessDeniedException("Couldn't save image file");
}
//Remove thumbnails and resized images in case if file is overwritten
if (!$saveAsNew && $saved) {
$resourceType = $workingFolder->getResourceType();
$thumbnailRepository->deleteThumbnails($resourceType, $workingFolder->getClientCurrentFolder(), $fileName);
$resizedImageRepository->deleteResizedImages($resourceType, $workingFolder->getClientCurrentFolder(), $fileName);
}
}
return array('saved' => (int) $saved, 'date' => Utils::formatDate(time()), 'size' => Utils::formatSize($imageInfo['size']));
}
示例3: execute
/**
* Main command method.
*
* @param Request $request Current request object
* @param WorkingFolder $workingFolder Current working folder object
*
* @return array
*
* @throws \Exception
*/
public function execute(Request $request, WorkingFolder $workingFolder)
{
$fileName = $request->get('fileName');
$backend = $workingFolder->getBackend();
if (!$workingFolder->containsFile($fileName)) {
throw new \Exception('File not found', Error::FILE_NOT_FOUND);
}
$fileMetadada = $backend->getMetadata(Path::combine($workingFolder->getPath(), $fileName));
return $fileMetadada;
}
示例4: doDelete
/**
* Deletes the current file.
*
* @return bool `true` if the file was deleted successfully.
*
* @throws \Exception
*/
public function doDelete()
{
if ($this->resourceType->getBackend()->delete($this->getFilePath())) {
$this->deleteThumbnails();
$this->deleteResizedImages();
$this->getCache()->delete(Path::combine($this->resourceType->getName(), $this->folder, $this->getFilename()));
return true;
} else {
$this->addError(Error::ACCESS_DENIED);
return false;
}
}
示例5: execute
public function execute(Request $request, Config $config, WorkingFolder $workingFolder, ResizedImageRepository $resizedImageRepository, CacheManager $cache)
{
$fileName = (string) $request->query->get('fileName');
list($requestedWidth, $requestedHeight) = Image::parseSize((string) $request->get('size'));
$downloadedFile = new DownloadedFile($fileName, $this->app);
$downloadedFile->isValid();
if (!Image::isSupportedExtension(pathinfo($fileName, PATHINFO_EXTENSION), $config->get('thumbnails.bmpSupported'))) {
throw new InvalidExtensionException('Unsupported image type or not image file');
}
Utils::removeSessionCacheHeaders();
$response = new Response();
$response->setPublic();
$response->setEtag(dechex($downloadedFile->getTimestamp()) . "-" . dechex($downloadedFile->getSize()));
$lastModificationDate = new \DateTime();
$lastModificationDate->setTimestamp($downloadedFile->getTimestamp());
$response->setLastModified($lastModificationDate);
if ($response->isNotModified($request)) {
return $response;
}
$imagePreviewCacheExpires = (int) $config->get('cache.imagePreview');
if ($imagePreviewCacheExpires > 0) {
$response->setMaxAge($imagePreviewCacheExpires);
$expireTime = new \DateTime();
$expireTime->modify('+' . $imagePreviewCacheExpires . 'seconds');
$response->setExpires($expireTime);
}
$cachedInfoPath = Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName);
$cachedInfo = $cache->get($cachedInfoPath);
$resultImage = null;
// Try to reuse existing resized image
if ($cachedInfo && isset($cachedInfo['width']) && isset($cachedInfo['height'])) {
// Fix received aspect ratio
$size = Image::calculateAspectRatio($requestedWidth, $requestedHeight, $cachedInfo['width'], $cachedInfo['height']);
$resizedImage = $resizedImageRepository->getResizedImageBySize($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $size['width'], $size['height']);
if ($resizedImage) {
$resultImage = Image::create($resizedImage->getImageData());
}
}
// Fallback - get and resize the original image
if (null === $resultImage) {
$resultImage = Image::create($downloadedFile->getContents(), $config->get('thumbnails.bmpSupported'));
$cache->set($cachedInfoPath, $resultImage->getInfo());
$resultImage->resize($requestedWidth, $requestedHeight);
}
$mimeType = $resultImage->getMimeType();
if (in_array($mimeType, array('image/bmp', 'image/x-ms-bmp'))) {
$mimeType = 'image/jpeg';
// Image::getData() by default converts resized images to JPG
}
$response->headers->set('Content-Type', $mimeType . '; name="' . $downloadedFile->getFileName() . '"');
$response->setContent($resultImage->getData());
return $response;
}
示例6: doRename
/**
* Renames current file
*
* @return bool true if file was renamed successfully
*
* @throws \Exception
*/
public function doRename()
{
$oldPath = Path::combine($this->getPath(), $this->getFilename());
$newPath = Path::combine($this->getPath(), $this->newFileName);
$backend = $this->resourceType->getBackend();
if ($backend->has($newPath)) {
throw new AlreadyExistsException('Target file already exists');
}
$this->deleteThumbnails();
$this->resourceType->getResizedImageRepository()->renameResizedImages($this->resourceType, $this->folder, $this->getFilename(), $this->newFileName);
$this->getCache()->move(Path::combine($this->resourceType->getName(), $this->folder, $this->getFilename()), Path::combine($this->resourceType->getName(), $this->folder, $this->newFileName));
return $backend->rename($oldPath, $newPath);
}
示例7: doMove
/**
* Moves the current file.
*
* @return bool `true` if the file was moved successfully.
*
* @throws \Exception
*/
public function doMove()
{
$originalFilePath = $this->getFilePath();
$originalFileName = $this->getFilename();
// Save original file name - it may be autorenamed when copied
if (parent::doCopy()) {
// Remove source file
$this->deleteThumbnails();
$this->resourceType->getResizedImageRepository()->deleteResizedImages($this->resourceType, $this->folder, $originalFileName);
$this->getCache()->delete(Path::combine($this->resourceType->getName(), $this->folder, $originalFileName));
return $this->resourceType->getBackend()->delete($originalFilePath);
}
return false;
}
示例8: execute
public function execute(WorkingFolder $workingFolder)
{
$directories = $workingFolder->listDirectories();
$data = new \stdClass();
$data->folders = array();
$backend = $workingFolder->getBackend();
$resourceType = $workingFolder->getResourceType();
foreach ($directories as $directory) {
$data->folders[] = array('name' => $directory['basename'], 'hasChildren' => $backend->containsDirectories($resourceType, Path::combine($workingFolder->getClientCurrentFolder(), $directory['basename'])), 'acl' => $directory['acl']);
}
// Sort folders
usort($data->folders, function ($a, $b) {
return strnatcasecmp($a['name'], $b['name']);
});
return $data;
}
示例9: execute
public function execute(Request $request, WorkingFolder $workingFolder, EventDispatcher $dispatcher, CacheManager $cache, ResizedImageRepository $resizedImageRepository, ThumbnailRepository $thumbnailRepository)
{
$fileName = $request->query->get('fileName');
$editedFile = new EditedFile($fileName, $this->app);
$saveAsNew = false;
if (!$editedFile->exists()) {
$saveAsNew = true;
$editedFile->saveAsNew(true);
}
if (!$editedFile->isValid()) {
throw new InvalidUploadException('Invalid file provided');
}
if (!Image::isSupportedExtension($editedFile->getExtension())) {
throw new InvalidExtensionException('Unsupported image type or not image file');
}
$imageFormat = Image::mimeTypeFromExtension($editedFile->getExtension());
$uploadedData = $request->get('content');
if (null === $uploadedData || strpos($uploadedData, 'data:image/png;base64,') !== 0) {
throw new InvalidUploadException('Invalid upload. Expected base64 encoded PNG image.');
}
$data = explode(',', $uploadedData);
$data = isset($data[1]) ? base64_decode($data[1]) : false;
if (!$data) {
throw new InvalidUploadException();
}
$uploadedImage = Image::create($data);
$newContents = $uploadedImage->getData($imageFormat);
$editFileEvent = new EditFileEvent($this->app, $editedFile, $newContents);
$cache->set(Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName), $uploadedImage->getInfo());
$dispatcher->dispatch(CKFinderEvent::SAVE_IMAGE, $editFileEvent);
$saved = false;
if (!$editFileEvent->isPropagationStopped()) {
$saved = $editedFile->setContents($editFileEvent->getNewContents());
//Remove thumbnails and resized images in case if file is overwritten
if (!$saveAsNew && $saved) {
$resourceType = $workingFolder->getResourceType();
$thumbnailRepository->deleteThumbnails($resourceType, $workingFolder->getClientCurrentFolder(), $fileName);
$resizedImageRepository->deleteResizedImages($resourceType, $workingFolder->getClientCurrentFolder(), $fileName);
}
}
return array('saved' => (int) $saved, 'date' => Utils::formatDate(time()));
}
示例10: execute
public function execute(Request $request, WorkingFolder $workingFolder, ResizedImageRepository $resizedImageRepository, Config $config, CacheManager $cache)
{
$fileName = $request->get('fileName');
$sizes = $request->get('sizes');
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
if (!Image::isSupportedExtension($ext)) {
throw new InvalidRequestException('Invalid file extension');
}
if ($sizes) {
$sizes = explode(',', $sizes);
if (array_diff($sizes, array_keys($config->get('images.sizes')))) {
throw new InvalidRequestException(sprintf('Invalid size requested (%s)', $request->get('sizes')));
}
}
$data = array();
$cachedInfo = $cache->get(Path::combine($workingFolder->getResourceType()->getName(), $workingFolder->getClientCurrentFolder(), $fileName));
if ($cachedInfo && isset($cachedInfo['width']) && isset($cachedInfo['height'])) {
$data['originalSize'] = sprintf("%dx%d", $cachedInfo['width'], $cachedInfo['height']);
}
$resizedImages = $resizedImageRepository->getResizedImagesList($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $sizes ?: array());
$data['resized'] = $resizedImages;
return $data;
}
示例11: execute
public function execute(WorkingFolder $workingFolder, Request $request, Config $config)
{
$fileName = $request->get('fileName');
$thumbnail = $request->get('thumbnail');
$fileNames = (array) $request->get('fileNames');
if (!empty($fileNames)) {
$urls = array();
foreach ($fileNames as $fileName) {
if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException(sprintf('Invalid file name: %s', $fileName));
}
$urls[$fileName] = $workingFolder->getFileUrl($fileName);
}
return array('urls' => $urls);
}
if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters')) || $thumbnail && !File::isValidName($thumbnail, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException('Invalid file name');
}
if (!$workingFolder->containsFile($fileName)) {
throw new FileNotFoundException();
}
return array('url' => $workingFolder->getFileUrl($thumbnail ? Path::combine(ResizedImage::DIR, $fileName, $thumbnail) : $fileName));
}
示例12: getFilePath
/**
* Returns backend-relative file path.
*
* @return string file path
*/
public function getFilePath()
{
return Path::combine($this->getPath(), $this->getFilename());
}
示例13: registerStreamLogger
/**
* Registers stream handler for errors logging
*/
public function registerStreamLogger()
{
$app = $this;
/* @var $logsBackend \CKSource\CKFinder\Backend\Backend */
$logsBackend = $app['backend_factory']->getPrivateDirBackend('logs');
$adapter = $logsBackend->getAdapter();
if ($adapter instanceof LocalFSAdapter) {
$logsDir = $app['config']->getPrivateDirPath('logs');
$errorLogPath = Path::combine($logsDir, 'error.log');
$logPath = $adapter->applyPathPrefix($errorLogPath);
$app['logger']->pushHandler(new StreamHandler($logPath));
}
}
示例14: create
/**
* Creates a thumbnail
*
* @return bool
*
* @throws \Exception
*/
public function create()
{
$sourceBackend = $this->sourceFileResourceType->getBackend();
$sourceFilePath = Path::combine($this->sourceFileResourceType->getDirectory(), $this->sourceFileDir, $this->sourceFileName);
if ($sourceBackend->isHiddenFile($this->sourceFileName) || !$sourceBackend->has($sourceFilePath)) {
throw new FileNotFoundException('Thumbnail::create(): Source file not found');
}
$image = Image::create($sourceBackend->read($sourceFilePath), $this->thumbnailRepository->isBitmapSupportEnabled());
// Update cached info about image
$app = $this->thumbnailRepository->getContainer();
$app['cache']->set(Path::combine($this->sourceFileResourceType->getName(), $this->sourceFileDir, $this->sourceFileName), $image->getInfo());
$image->resize($this->adjustedSizeInfo['width'], $this->adjustedSizeInfo['height'], $this->adjustedSizeInfo['quality']);
$this->resizedImageData = $image->getData();
$this->resizedImageSize = $image->getDataSize();
$this->resizedImageMimeType = $image->getMimeType();
unset($image);
}
示例15: getFilePath
/**
* Returns backend-relative resized image file path
*
* @return string
*/
public function getFilePath()
{
return Path::combine($this->getDirectory(), $this->getFileName());
}