本文整理汇总了PHP中Cake\Filesystem\Folder::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::create方法的具体用法?PHP Folder::create怎么用?PHP Folder::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\Folder
的用法示例。
在下文中一共展示了Folder::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* This function is used to uplodad file in /uploads/YEAR/MONTH directory
* and to create Content record contextually.
*
*
* @param type $inputfile
* @param string $destfile
* @return boolean
*/
public function upload($inputfile, $destfile = null)
{
if (strlen(trim($inputfile['name'])) === 0) {
return FALSE;
}
$filename = strtolower($inputfile['name']);
$sourcefile = $inputfile['tmp_name'];
$file = new \Cake\Filesystem\File($sourcefile, true, 0775);
$CONTENT_YEAR = date('Y');
$CONTENT_MONTH = date('m');
$UPLOAD_DIR = $this->path;
$folder_dest = new Folder($UPLOAD_DIR);
if (!$folder_dest->inCakePath($folder_dest->pwd() . DS . $CONTENT_YEAR)) {
$folder_dest->create($folder_dest->pwd() . DS . $CONTENT_YEAR);
}
$folder_dest->cd($CONTENT_YEAR);
if (!$folder_dest->inCakePath($folder_dest->pwd() . DS . $CONTENT_MONTH)) {
$folder_dest->create($folder_dest->pwd() . DS . $CONTENT_MONTH);
}
$folder_dest->cd($CONTENT_MONTH);
$path = DS . $CONTENT_YEAR . DS . $CONTENT_MONTH . DS;
$permittedFilename = $this->getPermittedFilename($UPLOAD_DIR . $path, $filename);
$destfile = $folder_dest->pwd() . DS . $permittedFilename;
if ($file->copy($destfile, true)) {
return $path . $permittedFilename;
} else {
return FALSE;
}
}
示例2: setUp
/**
* Cria um plugin de teste e o carrega para conseguir rodar os testes.
*/
public function setUp()
{
parent::setUp();
$testData = ['full_path' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS, 'config_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'config' . DS, 'css_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'css' . DS, 'js_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'js' . DS, 'img_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'img' . DS, 'packages_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'packages' . DS];
$pluginFolder = new Folder($testData['full_path'], self::CREATE_FOLDER_IF_NOT_EXISTS, self::PLUGIN_FOLDER_PERMISSIONS);
$pluginFolder->create($testData['config_folder']);
$pluginFolder->create($testData['css_folder']);
$pluginFolder->create($testData['js_folder']);
$pluginFolder->create($testData['img_folder']);
$pluginFolder->create($testData['packages_folder'] . 'sample_package');
$defaultSettingsFile = new File($testData['config_folder'] . 'default_settings.php', true);
$defaultSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.ThemeInstallerTest.Settings' => \n\t\t\t\t\t['Default' => true]\n\t\t\t\t]; \n\t\t?>");
$defaultSettingsFile->close();
$file = new File($testData['css_folder'] . 'sample.css', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['js_folder'] . 'sample.js', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.css', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.js', true);
$file->write('#id { }');
$file->close();
$bootstrapFile = new File($testData['config_folder'] . 'bootstrap.php', true);
$bootstrapFile->close();
}
示例3: testLoadList
/**
* Test plugin load by list.
*
* @return void
*/
public function testLoadList()
{
$Folder = new Folder();
$pluginsDir = APP_ROOT . 'Plugins' . DS;
$TestPlgPath = $pluginsDir . 'PluginTest';
$Folder->create($TestPlgPath, 0777);
new File($TestPlgPath . '/config/bootstrap.php', true);
new File($TestPlgPath . '/config/routes.php', true);
$NoRoutesPlgPath = $pluginsDir . 'NoRoutes';
$Folder->create($NoRoutesPlgPath, 0777);
new File($NoRoutesPlgPath . '/config/bootstrap.php', true);
$NoBootstrapPlgPath = $pluginsDir . 'NoBootstrap';
$Folder->create($NoBootstrapPlgPath, 0777);
new File($NoBootstrapPlgPath . '/config/routes.php', true);
$NoConfigPlgPath = $pluginsDir . 'NoConfig';
$Folder->create($NoConfigPlgPath, 0777);
Plugin::load('Migrations');
Plugin::loadList(['NoConfig', 'NoRoutes', 'PluginTest', 'Migrations', 'NoBootstrap']);
$this->assertTrue(Plugin::loaded('NoBootstrap'));
$this->assertTrue(Plugin::loaded('PluginTest'));
$this->assertTrue(Plugin::loaded('NoRoutes'));
$this->assertTrue(Plugin::loaded('NoConfig'));
// Check virtual paths.
$this->assertSame(1, count(vPath()->getPaths('NoBootstrap:')));
$this->assertSame(1, count(vPath()->getPaths('PluginTest:')));
$this->assertSame(1, count(vPath()->getPaths('NoRoutes:')));
$this->assertSame(1, count(vPath()->getPaths('NoConfig:')));
$Folder->delete($TestPlgPath);
$Folder->delete($NoRoutesPlgPath);
$Folder->delete($NoConfigPlgPath);
$Folder->delete($NoBootstrapPlgPath);
}
示例4: beforeSave
/**
* Check if there is some files to upload and modify the entity before
* it is saved.
*
* At the end, for each files to upload, unset their "virtual" property.
*
* @param Event $event The beforeSave event that was fired.
* @param Entity $entity The entity that is going to be saved.
*
* @throws \LogicException When the path configuration is not set.
* @throws \ErrorException When the function to get the upload path failed.
*
* @return void
*/
public function beforeSave(Event $event, Entity $entity)
{
$config = $this->_config;
foreach ($config['fields'] as $field => $fieldOption) {
$data = $entity->toArray();
$virtualField = $field . $config['suffix'];
if (!isset($data[$virtualField]) || !is_array($data[$virtualField])) {
continue;
}
$file = $entity->get($virtualField);
if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
continue;
}
if (!isset($fieldOption['path'])) {
throw new \LogicException(__('The path for the {0} field is required.', $field));
}
if (isset($fieldOption['prefix']) && (is_bool($fieldOption['prefix']) || is_string($fieldOption['prefix']))) {
$this->_prefix = $fieldOption['prefix'];
}
$extension = (new File($file['name'], false))->ext();
$uploadPath = $this->_getUploadPath($entity, $fieldOption['path'], $extension);
if (!$uploadPath) {
throw new \ErrorException(__('Error to get the uploadPath.'));
}
$folder = new Folder($this->_config['root']);
$folder->create($this->_config['root'] . dirname($uploadPath));
if ($this->_moveFile($entity, $file['tmp_name'], $uploadPath, $field, $fieldOption)) {
if (!$this->_prefix) {
$this->_prefix = '';
}
$entity->set($field, $this->_prefix . $uploadPath);
}
$entity->unsetProperty($virtualField);
}
}
示例5: beforeMarshal
public function beforeMarshal(Event $event, $data, $options)
{
$config = $this->_config;
foreach ($config['fields'] as $fieldKey => $fieldValue) {
$virtualField = $fieldKey;
$file = $data[$fieldKey];
if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
continue;
}
if (!isset($fieldValue['path'])) {
throw new \LogicException(__('The path for the {0} field is required.', $fieldKey));
}
if (isset($fieldValue['prefix']) && (is_bool($fieldValue['prefix']) || is_string($fieldValue['prefix']))) {
$this->_prefix = $fieldValue['prefix'];
}
$extension = (new File($file['name'], false))->ext();
$uploadPath = $this->_getUploadPath($data, $fieldValue['path'], $extension);
if (!$uploadPath) {
throw new \ErrorException(__('Error to get the uploadPath.'));
}
$folder = new Folder($this->_config['root']);
$folder->create($this->_config['root'] . dirname($uploadPath));
if ($this->_moveFile($data, $file['tmp_name'], $uploadPath, $fieldKey, $fieldValue)) {
if (!$this->_prefix) {
$this->_prefix = '';
}
$data[$fieldKey] = $uploadPath;
}
}
}
示例6: scanFolder
/**
* Scan folder by path.
*
* @param null $path
* @return void|\Cake\Network\Response
*/
public function scanFolder($path = null)
{
if (!$path) {
$path = WWW_ROOT;
}
$Folder = new Folder();
$_path = $this->request->query('path') ? $this->request->query('path') : $path;
if (!is_dir($_path)) {
$Folder->create($_path);
}
$_path = realpath($_path) . DS;
$regex = '/^' . preg_quote(realpath($path), '/') . '/';
if (preg_match($regex, $_path) == false) {
$this->_controller->Flash->error(__d('file_manager', 'Path {0} is restricted', $_path));
return $this->_controller->redirect(['action' => 'browse']);
}
$blacklist = ['.git', '.svn', '.CVS'];
$regex = '/(' . preg_quote(implode('|', $blacklist), '.') . ')/';
if (in_array(basename($_path), $blacklist) || preg_match($regex, $_path)) {
$this->_controller->Flash->error(__d('file_manager', 'Path %s is restricted', $_path));
return $this->_controller->redirect(['action' => 'browse']);
}
$Folder->path = $_path;
$content = $Folder->read();
$this->_controller->set('path', $_path);
$this->_controller->set('content', $content);
}
示例7: removeAndCreateFolder
private function removeAndCreateFolder($path)
{
$dir = new Folder($path);
$dir->delete();
$dir->create($path);
$file = new File($path . DS . 'empty');
$file->create();
}
示例8: testExistTheme
/**
* Test exist theme plugin.
*
* @return void
*/
public function testExistTheme()
{
$name = Configure::read('Theme.site');
$path = $this->_paths[1] . $name;
$this->_folder->create($path);
$this->assertSame($path, Theme::exist($name));
$this->_folder->delete($path);
}
示例9: afterSave
public function afterSave(Event $event, Entity $site, \ArrayObject $options)
{
$sitePath = WWW_ROOT . '..' . DS . self::SITES_DIR . DS . 'site' . $site->id;
$folder = new Folder();
if (!$folder->create($sitePath, 0755)) {
throw new InternalErrorException('Error create site files');
}
$indexHtml = new File($sitePath . DS . 'index.html', true, 0644);
$indexHtml->write($site->content);
}
示例10: checkIfSubfolderExistsAndCreateIfFalseAndReturnPath
private function checkIfSubfolderExistsAndCreateIfFalseAndReturnPath($folder, $subfolder)
{
$folderObject = new Folder($folder);
$folder = $folderObject->read();
if (!in_array($subfolder, $folder[0])) {
$folderObject->create($subfolder);
}
$folderObject->cd($subfolder);
return $folderObject->path;
}
示例11: addDirImg
public function addDirImg()
{
if ($this->request->is('post')) {
$dossier_nom = $this->request->data['dossier_nom'];
$folder = new Folder(ROOT . '/plugins/Admin/webroot/img/projets/');
$folder->create($dossier_nom);
$this->Flash->success(__('Le dossier a été créé avec succès !'));
return $this->redirect(['action' => 'index']);
}
$this->set('data', ['title' => __("Ajouter un dossier d'images")]);
$this->set(compact('data'));
}
示例12: setUp
/**
* Cria um plugin de teste e o carrega para conseguir rodar os testes.
*/
public function setUp()
{
parent::setUp();
$testPluginData = ['full_path' => ROOT . DS . 'plugins' . DS . 'PluginInstallerTest' . DS, 'config_folder' => ROOT . DS . 'plugins' . DS . 'PluginInstallerTest' . DS . 'config' . DS];
$pluginFolder = new Folder($testPluginData['full_path'], self::CREATE_FOLDER_IF_NOT_EXISTS, self::PLUGIN_FOLDER_PERMISSIONS);
$pluginFolder->create('config');
$defaultSettingsFile = new File($testPluginData['config_folder'] . 'default_settings.php', true);
$defaultSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.PluginInstallerTest.Settings' => \n\t\t\t\t\t['Default' => true]\n\t\t\t\t]; \n\t\t?>");
$defaultSettingsFile->close();
$bootstrapFile = new File($testPluginData['config_folder'] . 'bootstrap.php', true);
$bootstrapFile->close();
Plugin::load('PluginInstallerTest', ['routes' => false, 'bootstrap' => false]);
}
示例13: create
public function create($path = null)
{
$root = WWW_ROOT;
$fullPath = $root . $path;
if ($this->request->is('post')) {
$folderName = $this->request->data['name'];
$folder = new Folder($fullPath);
if ($folder->create($folderName)) {
$this->Flash->success(__('The folder "{0}" has been created.', $folderName));
return $this->redirect(['action' => 'index', $path]);
}
$this->Flash->error(__('The folder "{0}" could not be created.', $folderName));
}
}
示例14: install
/**
* Faz uma instalação básica do plugin.
* A instalação consiste em criar o arquivo de configurações do plugin no diretório apropriado.
* Este método é chamado pelo método PluginStarter::load() quando necessário.
*
* @param string $pluginName O nome do plugin a ser instalado.
* @return void
*/
public function install($pluginName)
{
$settingsFileFolder = $this->pluginInstallationFolder . $pluginName . DS;
if (Plugin::loaded($pluginName)) {
$defaultFile = Plugin::path($pluginName) . 'config' . DS . 'default_settings.php';
$folderHandler = new Folder();
if (!$folderHandler->cd($settingsFileFolder)) {
$folderHandler->create($settingsFileFolder);
}
$fileHandler = new File($defaultFile);
$fileHandler->copy($settingsFileFolder . 'settings.php');
$fileHandler->close();
}
}
示例15: upload
/**
* Upload a file to the server
* @param upload - file to upload
* @param owner - contains model name and id associated with the file
* @return array - uploaded file information or null for failure
*/
public function upload($upload, $owner = null)
{
// Filesize verification
if ($upload['size'] == 0) {
return null;
}
if ($upload['size'] > $this->maxFileSize) {
return null;
}
$path = $this->storagePath;
// Owner separated storage
if ($this->storeOwner == true && $owner) {
// Directory should be lower case
$ownerTable = strtolower($owner->source());
// Owner specific directory must be unique (uuid)
$ownerDirectory = Inflector::singularize($ownerTable) . $owner->id;
$path .= DS . $ownerTable . DS . $ownerDirectory;
}
// If types do not match, default subdir is 'document'
$subdir = 'document';
$types = ['image', 'audio', 'video'];
// Check for filetype
foreach ($types as $type) {
if (strstr($upload['type'], $type)) {
$subdir = $type;
}
}
// Append the subdirectory (filtype directory)
$path .= DS . $subdir;
// Make directory if there is none
$directory = new Folder();
if (!$directory->create(WWW_ROOT . DS . $path)) {
return null;
}
// Find file in tmp
$file = new File($upload['tmp_name']);
// File's name must be unique, making the path unique as well
$name = time() . '_' . Inflector::slug($upload['name']);
$path .= DS . $name;
// Copy from tmp to perm (create)
if ($file->copy($path)) {
return ['original_name' => $upload['name'], 'name' => $name, 'path' => $path, 'type' => $upload['type'], 'size' => $upload['size']];
} else {
return null;
}
}