本文整理汇总了PHP中Folder::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::write方法的具体用法?PHP Folder::write怎么用?PHP Folder::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find_or_make
/**
* Find the given folder or create it both as {@link Folder} database records
* and on the filesystem. If necessary, creates parent folders as well.
*
* @param $folderPath string Absolute or relative path to the file.
* If path is relative, its interpreted relative to the "assets/" directory.
* @return Folder
*/
public static function find_or_make($folderPath)
{
// Create assets directory, if it is missing
if (!file_exists(ASSETS_PATH)) {
Filesystem::makeFolder(ASSETS_PATH);
}
$folderPath = trim(Director::makeRelative($folderPath));
// replace leading and trailing slashes
$folderPath = preg_replace('/^\\/?(.*)\\/?$/', '$1', $folderPath);
$parts = explode("/", $folderPath);
$parentID = 0;
$item = null;
foreach ($parts as $part) {
if (!$part) {
continue;
}
// happens for paths with a trailing slash
$item = DataObject::get_one("Folder", sprintf("\"Name\" = '%s' AND \"ParentID\" = %d", Convert::raw2sql($part), (int) $parentID));
if (!$item) {
$item = new Folder();
$item->ParentID = $parentID;
$item->Name = $part;
$item->Title = $part;
$item->write();
}
if (!file_exists($item->getFullPath())) {
Filesystem::makeFolder($item->getFullPath());
}
$parentID = $item->ID;
}
return $item;
}
示例2: find_or_make
/**
* Find the given folder or create it as a database record
*
* @param string $folderPath Directory path relative to assets root
* @return Folder|null
*/
public static function find_or_make($folderPath)
{
// replace leading and trailing slashes
$folderPath = preg_replace('/^\\/?(.*)\\/?$/', '$1', trim($folderPath));
$parts = explode("/", $folderPath);
$parentID = 0;
$item = null;
$filter = FileNameFilter::create();
foreach ($parts as $part) {
if (!$part) {
continue;
// happens for paths with a trailing slash
}
// Ensure search includes folders with illegal characters removed, but
// err in favour of matching existing folders if $folderPath
// includes illegal characters itself.
$partSafe = $filter->filter($part);
$item = Folder::get()->filter(array('ParentID' => $parentID, 'Name' => array($partSafe, $part)))->first();
if (!$item) {
$item = new Folder();
$item->ParentID = $parentID;
$item->Name = $partSafe;
$item->Title = $part;
$item->write();
}
$parentID = $item->ID;
}
return $item;
}
示例3: testWritingSubsiteID
function testWritingSubsiteID()
{
$this->objFromFixture('Member', 'admin')->logIn();
$subsite = $this->objFromFixture('Subsite', 'domaintest1');
FileSubsites::$default_root_folders_global = true;
Subsite::changeSubsite(0);
$file = new File();
$file->write();
$file->onAfterUpload();
$this->assertEquals((int) $file->SubsiteID, 0);
Subsite::changeSubsite($subsite->ID);
$this->assertTrue($file->canEdit());
$file = new File();
$file->write();
$this->assertEquals((int) $file->SubsiteID, 0);
$this->assertTrue($file->canEdit());
FileSubsites::$default_root_folders_global = false;
Subsite::changeSubsite($subsite->ID);
$file = new File();
$file->write();
$this->assertEquals($file->SubsiteID, $subsite->ID);
// Test inheriting from parent folder
$folder = new Folder();
$folder->write();
$this->assertEquals($folder->SubsiteID, $subsite->ID);
FileSubsites::$default_root_folders_global = true;
$file = new File();
$file->ParentID = $folder->ID;
$file->onAfterUpload();
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
}
示例4: testCreateFromNameAndParentIDSetsFilename
public function testCreateFromNameAndParentIDSetsFilename()
{
$folder1 = $this->objFromFixture('Folder', 'folder1');
$newFolder = new Folder();
$newFolder->Name = 'CreateFromNameAndParentID';
$newFolder->ParentID = $folder1->ID;
$newFolder->write();
$this->assertEquals($folder1->Filename . 'CreateFromNameAndParentID/', $newFolder->Filename);
}
示例5: findOrMake
static function findOrMake($folder)
{
$parts = explode("/", $folder);
$parentID = 0;
foreach ($parts as $part) {
$item = DataObject::get_one("Folder", "Name = '{$part}' AND ParentID = {$parentID}");
if (!$item) {
$item = new Folder();
$item->ParentID = $parentID;
$item->Name = $part;
$item->Title = $part;
$item->write();
if (!file_exists($item->getFullPath())) {
mkdir($item->getFullPath(), Filesystem::$folder_create_mask);
}
}
$parentID = $item->ID;
}
return $item;
}
示例6: findOrMake
static function findOrMake($folderPath) {
$folderPath = trim(Director::makeRelative($folderPath));
// replace leading and trailing slashes
$folderPath = preg_replace('/^\/?(.*)\/?$/', '$1', $folderPath);
$parts = explode("/",$folderPath);
$parentID = 0;
foreach($parts as $part) {
$item = DataObject::get_one("Folder", "Name = '$part' AND ParentID = $parentID");
if(!$item) {
$item = new Folder();
$item->ParentID = $parentID;
$item->Name = $part;
$item->Title = $part;
$item->write();
if(!file_exists($item->getFullPath())) mkdir($item->getFullPath(),Filesystem::$folder_create_mask);
}
$parentID = $item->ID;
}
return $item;
}
示例7: addfolder
/**
* Add a new folder and return its details suitable for ajax.
*/
public function addfolder($request)
{
// Protect against CSRF on destructive action
if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400);
}
$parent = $_REQUEST['ParentID'] && is_numeric($_REQUEST['ParentID']) ? (int) $_REQUEST['ParentID'] : 0;
$name = isset($_REQUEST['Name']) ? basename($_REQUEST['Name']) : _t('AssetAdmin.NEWFOLDER', "NewFolder");
if ($parent) {
$parentObj = DataObject::get_by_id('File', $parent);
if (!$parentObj || !$parentObj->ID) {
$parent = 0;
}
}
// Get the folder to be created
if (isset($parentObj->ID)) {
$filename = $parentObj->FullPath . $name;
} else {
$filename = ASSETS_PATH . '/' . $name;
}
// Actually create
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$p = new Folder();
$p->ParentID = $parent;
$p->Name = $p->Title = basename($filename);
// Ensure uniqueness
$i = 2;
$baseFilename = substr($p->Filename, 0, -1) . '-';
while (file_exists($p->FullPath)) {
$p->Filename = $baseFilename . $i . '/';
$i++;
}
$p->write();
mkdir($p->FullPath);
chmod($p->FullPath, Filesystem::$file_create_mask);
if (isset($_REQUEST['returnID'])) {
return $p->ID;
} else {
return $this->returnItemToUser($p);
}
}
示例8: doAdd
/**
* Add a new group and return its details suitable for ajax.
*
* @todo Move logic into Folder class, and use LeftAndMain->doAdd() default implementation.
*/
public function doAdd($data, $form)
{
$class = $this->stat('tree_class');
// check create permissions
if (!singleton($class)->canCreate()) {
return Security::permissionFailure($this);
}
// check addchildren permissions
if (singleton($class)->hasExtension('Hierarchy') && isset($data['ParentID']) && is_numeric($data['ParentID']) && $data['ParentID']) {
$parentRecord = DataObject::get_by_id($class, $data['ParentID']);
if ($parentRecord->hasMethod('canAddChildren') && !$parentRecord->canAddChildren()) {
return Security::permissionFailure($this);
}
} else {
$parentRecord = null;
}
$parent = isset($data['ParentID']) && is_numeric($data['ParentID']) ? (int) $data['ParentID'] : 0;
$name = isset($data['Name']) ? basename($data['Name']) : _t('AssetAdmin.NEWFOLDER', "NewFolder");
if (!$parentRecord || !$parentRecord->ID) {
$parent = 0;
}
// Get the folder to be created
if ($parentRecord && $parentRecord->ID) {
$filename = $parentRecord->FullPath . $name;
} else {
$filename = ASSETS_PATH . '/' . $name;
}
// Actually create
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$record = new Folder();
$record->ParentID = $parent;
$record->Name = $record->Title = basename($filename);
// Ensure uniqueness
$i = 2;
$baseFilename = substr($record->Filename, 0, -1) . '-';
while (file_exists($record->FullPath)) {
$record->Filename = $baseFilename . $i . '/';
$i++;
}
$record->Name = $record->Title = basename($record->Filename);
$record->write();
mkdir($record->FullPath);
chmod($record->FullPath, Filesystem::config()->file_create_mask);
if ($parentRecord) {
return $this->redirect(Controller::join_links($this->Link('show'), $parentRecord->ID));
} else {
return $this->redirect($this->Link());
}
}
示例9: newfolder
/**
* Creates a new folder at the level of {@link KickAssetAdmin::$currentFolder}
*
* @param SS_HTTPRequest
* @return SS_HTTPResponse
*/
public function newfolder(SS_HTTPRequest $r)
{
$f = new Folder();
$f->ParentID = $this->currentFolder ? $this->currentFolder->ID : 0;
$f->Name = "New-Folder";
$f->Title = "New-Folder";
$f->write();
if (!file_exists($f->getFullPath())) {
Filesystem::makeFolder($f->getFullPath());
}
return $this->browse($r);
}
示例10: find_or_make_secured
/**
* Find the given folder or create it both as {@link Folder} database record
* and on the filesystem. If necessary, creates parent folders as well. If it's
* unable to find or make the folder, it will return null (as /assets is unable
* to be represented by a Folder {@link DataObject}).
*
* @param string $folderPath Absolute or relative path to the file.
* If path is relative, it's interpreted relative
* to the "assets/" directory.
* @return Folder | null
*/
public static function find_or_make_secured($folderPath)
{
// Create assets directory, if it is missing
if (!file_exists(ASSETS_PATH)) {
Filesystem::makeFolder(ASSETS_PATH);
}
$folderPath = trim(Director::makeRelative($folderPath));
// replace leading and trailing slashes
$folderPath = preg_replace('/^\\/?(.*)\\/?$/', '$1', $folderPath);
$parts = explode("/", $folderPath);
$parentID = 0;
$item = null;
$filter = FileNameFilter::create();
foreach ($parts as $part) {
if (!$part) {
continue;
// happens for paths with a trailing slash
}
// Ensure search includes folders with illegal characters removed, but
// err in favour of matching existing folders if $folderPath
// includes illegal characters itself.
$partSafe = $filter->filter($part);
$item = Folder::get()->filter(array('ParentID' => $parentID, 'Name' => array($partSafe, $part), 'CanViewType' => 'Anyone', 'CanEditType' => 'LoggedInUsers'))->first();
if (!$item) {
$item = new Folder();
$item->ParentID = $parentID;
$item->Name = $partSafe;
$item->Title = $part;
$item->Secured = true;
$item->write();
// when initial the secured root folder, set its CanViewType to be
if (!$parentID) {
$item->CanViewType = 'Anyone';
$item->CanEditType = 'LoggedInUsers';
}
}
if (!file_exists($item->getFullPath())) {
Filesystem::makeFolder($item->getFullPath());
}
$parentID = $item->ID;
}
return $item;
}
示例11: createUploadFolder
/**
* Creates the upload folder for payment images if it doesn't exist.
*
* @return void
*
* @author Sebastian Diel <sdiel@pixeltricks.de>,
* Sascha Koehler <skoehler@pixeltricks.de>
* @since 16.06.2014
*/
public function createUploadFolder()
{
$uploadsFolder = Folder::get()->filter('Name', 'Uploads')->first();
if (!$uploadsFolder) {
$uploadsFolder = new Folder();
$uploadsFolder->Name = 'Uploads';
$uploadsFolder->Title = 'Uploads';
$uploadsFolder->Filename = 'assets/Uploads/';
$uploadsFolder->write();
}
$this->uploadsFolder = $uploadsFolder;
}
示例12: addfolder
/**
* Add a new folder and return its details suitable for ajax.
*/
public function addfolder()
{
$parent = $_REQUEST['ParentID'] && is_numeric($_REQUEST['ParentID']) ? (int) $_REQUEST['ParentID'] : 0;
$name = isset($_REQUEST['Name']) ? basename($_REQUEST['Name']) : _t('AssetAdmin.NEWFOLDER', "NewFolder");
if ($parent) {
$parentObj = DataObject::get_by_id('File', $parent);
if (!$parentObj || !$parentObj->ID) {
$parent = 0;
}
}
// Get the folder to be created
if (isset($parentObj->ID)) {
$filename = $parentObj->FullPath . $name;
} else {
$filename = ASSETS_PATH . '/' . $name;
}
// Ensure uniqueness
$i = 2;
$baseFilename = $filename . '-';
while (file_exists($filename)) {
$filename = $baseFilename . $i;
$i++;
}
// Actually create
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
mkdir($filename);
chmod($filename, Filesystem::$file_create_mask);
// Create object
$p = new Folder();
$p->ParentID = $parent;
$p->Name = $p->Title = basename($filename);
$p->write();
if (isset($_REQUEST['returnID'])) {
return $p->ID;
} else {
return $this->returnItemToUser($p);
}
}