public function importUrlAction() { $success = true; $data = Tool::getHttpData($this->getParam("url")); $filename = basename($this->getParam("url")); $parentId = $this->getParam("id"); $parentAsset = Asset::getById(intval($parentId)); $filename = File::getValidFilename($filename); $filename = $this->getSafeFilename($parentAsset->getFullPath(), $filename); if (empty($filename)) { throw new \Exception("The filename of the asset is empty"); } // check for duplicate filename $filename = $this->getSafeFilename($parentAsset->getFullPath(), $filename); if ($parentAsset->isAllowed("create")) { $asset = Asset::create($parentId, array("filename" => $filename, "data" => $data, "userOwner" => $this->user->getId(), "userModification" => $this->user->getId())); $success = true; } else { \Logger::debug("prevented creating asset because of missing permissions"); } $this->_helper->json(array("success" => $success)); }
/** * @param string $name * @throws DAV\Exception\Forbidden */ public function createDirectory($name) { $user = AdminTool::getCurrentUser(); if ($this->asset->isAllowed("create")) { $asset = Asset::create($this->asset->getId(), ["filename" => Element\Service::getValidKey($name, "asset"), "type" => "folder", "userModification" => $user->getId(), "userOwner" => $user->getId()]); } else { throw new DAV\Exception\Forbidden(); } }
/** * @param string $name * @throws DAV\Exception\Forbidden */ function createDirectory($name) { $user = AdminTool::getCurrentUser(); if ($this->asset->isAllowed("create")) { $asset = Asset::create($this->asset->getId(), array("filename" => File::getValidFilename($name), "type" => "folder", "userModification" => $user->getId(), "userOwner" => $user->getId())); } else { throw new DAV\Exception\Forbidden(); } }
/** * @param string base64 * @return Asset */ public function convertToAsset($imgstr) { $uploadDir = PIMCORE_TMP_DIRECTORY . '/asset-temporary/'; $content = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $imgstr)); $name = uniqid() . '.png'; $file = $uploadDir . $name; $success = file_put_contents($file, $content); if ($success) { $parentAsset = Asset_Folder::getById(71); $asset = Asset::create($parentAsset->getId(), array("filename" => $name, "data" => file_get_contents($file))); return $asset; } else { return false; } }