示例#1
0
 /**
  * @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();
 }
示例#2
0
文件: avatar.php 项目: smaffulli/core
 /**
  * @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;
 }
示例#3
0
文件: avatar.php 项目: evanjt/core
 /**
  * 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);
 }
示例#4
0
	/**
	 * 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);
	}
示例#5
0
 /**
  * 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;
 }