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


PHP Folder::newFile方法代码示例

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


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

示例1: saveAttachment

 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @param int $accountId
  * @param string $folderId
  * @param string $messageId
  * @param string $attachmentId
  * @param string $targetPath
  * @return JSONResponse
  */
 public function saveAttachment($accountId, $folderId, $messageId, $attachmentId, $targetPath)
 {
     $mailBox = $this->getFolder($accountId, $folderId);
     $attachmentIds = [$attachmentId];
     if ($attachmentId === 0) {
         $m = $mailBox->getMessage($messageId);
         $attachmentIds = array_map(function ($a) {
             return $a['id'];
         }, $m->attachments);
     }
     foreach ($attachmentIds as $attachmentId) {
         $attachment = $mailBox->getAttachment($messageId, $attachmentId);
         $fileName = $attachment->getName();
         $fileParts = pathinfo($fileName);
         $fileName = $fileParts['filename'];
         $fileExtension = $fileParts['extension'];
         $fullPath = "{$targetPath}/{$fileName}.{$fileExtension}";
         $counter = 2;
         while ($this->userFolder->nodeExists($fullPath)) {
             $fullPath = "{$targetPath}/{$fileName} ({$counter}).{$fileExtension}";
             $counter++;
         }
         $newFile = $this->userFolder->newFile($fullPath);
         $newFile->putContent($attachment->getContents());
     }
     return new JSONResponse();
 }
开发者ID:jakobsack,项目名称:mail,代码行数:38,代码来源:messagescontroller.php

示例2: getFile

 /**
  * @inheritdoc
  */
 public function getFile($size)
 {
     $ext = $this->getExtention();
     if ($size === -1) {
         $path = 'avatar.' . $ext;
     } else {
         $path = 'avatar.' . $size . '.' . $ext;
     }
     try {
         $file = $this->folder->get($path);
     } catch (NotFoundException $e) {
         if ($size <= 0) {
             throw new NotFoundException();
         }
         $avatar = new OC_Image();
         /** @var File $file */
         $file = $this->folder->get('avatar.' . $ext);
         $avatar->loadFromData($file->getContent());
         if ($size !== -1) {
             $avatar->resize($size);
         }
         $file = $this->folder->newFile($path);
         $file->putContent($avatar->data());
     }
     return $file;
 }
开发者ID:smaffulli,项目名称:core,代码行数:29,代码来源:avatar.php

示例3: set

 /**
  * sets the users avatar
  * @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar
  * @throws \Exception if the provided file is not a jpg or png image
  * @throws \Exception if the provided image is not valid
  * @throws \OC\NotSquareException if the image is not square
  * @return void
  */
 public function set($data)
 {
     if ($data instanceof \OCP\IImage) {
         $img = $data;
         $data = $img->data();
     } else {
         $img = new OC_Image($data);
     }
     $type = substr($img->mimeType(), -3);
     if ($type === 'peg') {
         $type = 'jpg';
     }
     if ($type !== 'jpg' && $type !== 'png') {
         throw new \Exception($this->l->t("Unknown filetype"));
     }
     if (!$img->valid()) {
         throw new \Exception($this->l->t("Invalid image"));
     }
     if (!($img->height() === $img->width())) {
         throw new \OC\NotSquareException();
     }
     $this->remove();
     $this->folder->newFile('avatar.' . $type)->putContent($data);
 }
开发者ID:evanjt,项目名称:core,代码行数:32,代码来源:avatar.php

示例4: copyr

	/**
	 * copies a directory recursively by using streams
	 *
	 * @param string $source
	 * @param \OCP\Files\Folder $target
	 * @return void
	 */
	public static function copyr($source, \OCP\Files\Folder $target) {
		$dir = opendir($source);
		while (false !== ($file = readdir($dir))) {
			if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
				if (is_dir($source . '/' . $file)) {
					$child = $target->newFolder($file);
					self::copyr($source . '/' . $file, $child);
				} else {
					$child = $target->newFile($file);
					stream_copy_to_stream(fopen($source . '/' . $file,'r'), $child->fopen('w'));
				}
			}
		}
		closedir($dir);
	}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:22,代码来源:util.php

示例5: addFile

 /**
  * Copies the content of one file to another
  *
  * @param Folder $folder
  * @param string $sourceName
  * @param string $destinationName
  *
  * @return File
  */
 private function addFile($folder, $sourceName, $destinationName)
 {
     $file = $folder->newFile($destinationName);
     $fileData = file_get_contents(__DIR__ . '/../../_data/' . $sourceName);
     $file->putContent($fileData);
     return $file;
 }
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:16,代码来源:DataSetup.php


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