本文整理汇总了PHP中drupal_mkdir函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_mkdir函数的具体用法?PHP drupal_mkdir怎么用?PHP drupal_mkdir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_mkdir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file_upload
function file_upload($fileUrl, $file_path = "files")
{
//echo $file_path;
// echo 's3://'.$fileUrl;
$file_temp = file_get_contents('http://www.voteapps.com/' . $fileUrl);
//print_r();
//Saves a file to the specified destination and creates a database entry.
if (!file_exists($public_path . '/apkfiles')) {
drupal_mkdir($public_path . '/apkfiles');
}
$file_arry = file_save_data($file_temp, 's3://' . $fileUrl, FILE_EXISTS_REPLACE);
//print_r($file_arry);
//转存视频和图片
if ($file_arry) {
// echo "</br>上传成功...";
return $file_arry;
} else {
//echo "</br>再次尝试上传...";
$file_arry = file_save_data($file_temp, 's3://' . $fileUrl, FILE_EXISTS_REPLACE);
if ($file_arry) {
//清空视频
//unlink($$fileUrl);
// echo "</br>上传成功...";
return $file_arry;
} else {
//清空视频
// unlink($$fileUrl);
// echo "</br>上传失败...";
return $file_arry;
//header('HTTP/1.1 500 Internal Server Error');
//exit;
}
}
}
示例2: _os_files_deprivatize_file
/**
* Moves a private managed file to the public directory.
*/
function _os_files_deprivatize_file($fid)
{
$file = file_load($fid);
// Builds new public path.
$dest_uri = str_replace('private://', 'public://', $file->uri);
$dest_path = _os_files_deprivatize_get_dest_path($dest_uri);
// Creates the destination folder if it doesn't exist.
if (!is_dir($dest_path)) {
// Creates the folder.
drupal_mkdir($dest_path, NULL, TRUE);
}
$moved_file = @file_move($file, $dest_uri);
if ($moved_file) {
drush_log(dt('File @name moved successfully.', array('@name' => $file->filename)), 'success');
} else {
drush_log(dt('Error moving file @name.', array('@name' => $file->filename)), 'error');
return FALSE;
}
$file->uri = $moved_file->uri;
$file_moved = file_save($file);
if (isset($file_moved->fid)) {
drush_log(dt('[O] File @name updated successfully.', array('@name' => $file->filename)), 'success');
return TRUE;
} else {
drush_log(dt('[!] Error updating file @name.', array('@name' => $file->filename)), 'error');
return FALSE;
}
}
示例3: testFileCheckLocalDirectoryHandling
/**
* Test local directory handling functions.
*/
function testFileCheckLocalDirectoryHandling()
{
$site_path = $this->container->get('site.path');
$directory = $site_path . '/files';
// Check a new recursively created local directory for correct file system
// permissions.
$parent = $this->randomMachineName();
$child = $this->randomMachineName();
// Files directory already exists.
$this->assertTrue(is_dir($directory), t('Files directory already exists.'), 'File');
// Make files directory writable only.
$old_mode = fileperms($directory);
// Create the directories.
$parent_path = $directory . DIRECTORY_SEPARATOR . $parent;
$child_path = $parent_path . DIRECTORY_SEPARATOR . $child;
$this->assertTrue(drupal_mkdir($child_path, 0775, TRUE), t('No error reported when creating new local directories.'), 'File');
// Ensure new directories also exist.
$this->assertTrue(is_dir($parent_path), t('New parent directory actually exists.'), 'File');
$this->assertTrue(is_dir($child_path), t('New child directory actually exists.'), 'File');
// Check that new directory permissions were set properly.
$this->assertDirectoryPermissions($parent_path, 0775);
$this->assertDirectoryPermissions($child_path, 0775);
// Check that existing directory permissions were not modified.
$this->assertDirectoryPermissions($directory, $old_mode);
// Check creating a directory using an absolute path.
$absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName();
$this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
$this->assertDirectoryPermissions($absolute_path, 0775);
}
示例4: superhero_preprocess_page
/**
* Preprocess Page
*/
function superhero_preprocess_page(&$vars)
{
$theme = superhero_get_theme();
$theme->page =& $vars;
$vars['attributes_array']['class'] = array('body');
// Primary nav
$vars['primary_nav'] = FALSE;
if ($vars['main_menu']) {
// Build links
$vars['primary_nav'] = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
// Provide default theme wrapper function
$vars['primary_nav']['#theme_wrappers'] = array('menu_tree__primary');
}
$default_preset = $theme->settings['default_preset'];
$force = false;
$superhero_base_url = variable_get('superhero_base_url', '');
global $base_url;
if ($superhero_base_url != $base_url) {
$force = true;
}
variable_set('superhero_base_url', $base_url);
require_once dirname(__FILE__) . '/includes/superhero_scss.php';
$scss = new Superhero_scss($theme);
if (!file_exists('public://css')) {
drupal_mkdir('public://css');
}
$file = $scss->outputFile('public://css/' . $theme->theme . '-theme-preset' . ($default_preset + 1) . '.css', $force);
drupal_add_css($file, array('type' => 'file', 'group' => CSS_THEME));
}
示例5: testFileRetrieving
/**
* Invokes system_retrieve_file() in several scenarios.
*/
function testFileRetrieving()
{
// Test 404 handling by trying to fetch a randomly named file.
drupal_mkdir($sourcedir = 'public://' . $this->randomMachineName());
$filename = 'Файл для тестирования ' . $this->randomMachineName();
$url = file_create_url($sourcedir . '/' . $filename);
$retrieved_file = system_retrieve_file($url);
$this->assertFalse($retrieved_file, 'Non-existent file not fetched.');
// Actually create that file, download it via HTTP and test the returned path.
file_put_contents($sourcedir . '/' . $filename, 'testing');
$retrieved_file = system_retrieve_file($url);
// URLs could not contains characters outside the ASCII set so $filename
// has to be encoded.
$encoded_filename = rawurlencode($filename);
$this->assertEqual($retrieved_file, 'public://' . $encoded_filename, 'Sane path for downloaded file returned (public:// scheme).');
$this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (public:// scheme).');
$this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (public:// scheme).');
file_unmanaged_delete($retrieved_file);
// Test downloading file to a different location.
drupal_mkdir($targetdir = 'temporary://' . $this->randomMachineName());
$retrieved_file = system_retrieve_file($url, $targetdir);
$this->assertEqual($retrieved_file, "{$targetdir}/{$encoded_filename}", 'Sane path for downloaded file returned (temporary:// scheme).');
$this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (temporary:// scheme).');
$this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (temporary:// scheme).');
file_unmanaged_delete($retrieved_file);
file_unmanaged_delete_recursive($sourcedir);
file_unmanaged_delete_recursive($targetdir);
}
示例6: mylog
function mylog($data, $file_name)
{
if (file_destination('public://log', FILE_EXISTS_ERROR)) {
// The file doesn't exist. do something
drupal_mkdir('public://log');
}
file_save_data(print_r($data, true), "public://log/{$file_name}", FILE_EXISTS_REPLACE);
}
示例7: directory_cache
public static function directory_cache($subdir = '')
{
$dir = UPAL_TMP . '/' . $subdir;
if (!file_exists($dir)) {
drupal_mkdir($dir, NULL, TRUE);
}
return $dir;
}
示例8: testReadOnlyBehavior
/**
* Test read-only specific behavior.
*/
function testReadOnlyBehavior()
{
// Generate a test file
$filename = $this->randomMachineName();
$site_path = $this->container->get('site.path');
$filepath = $site_path . '/files/' . $filename;
file_put_contents($filepath, $filename);
// Generate a read-only stream wrapper instance
$uri = $this->scheme . '://' . $filename;
file_stream_wrapper_get_instance_by_scheme($this->scheme);
// Attempt to open a file in read/write mode
$handle = @fopen($uri, 'r+');
$this->assertFalse($handle, 'Unable to open a file for reading and writing with the read-only stream wrapper.');
// Attempt to open a file in binary read mode
$handle = fopen($uri, 'rb');
$this->assertTrue($handle, 'Able to open a file for reading in binary mode with the read-only stream wrapper.');
$this->assertTrue(fclose($handle), 'Able to close file opened in binary mode using the read_only stream wrapper.');
// Attempt to open a file in text read mode
$handle = fopen($uri, 'rt');
$this->assertTrue($handle, 'Able to open a file for reading in text mode with the read-only stream wrapper.');
$this->assertTrue(fclose($handle), 'Able to close file opened in text mode using the read_only stream wrapper.');
// Attempt to open a file in read mode
$handle = fopen($uri, 'r');
$this->assertTrue($handle, 'Able to open a file for reading with the read-only stream wrapper.');
// Attempt to change file permissions
$this->assertFalse(@chmod($uri, 0777), 'Unable to change file permissions when using read-only stream wrapper.');
// Attempt to acquire an exclusive lock for writing
$this->assertFalse(@flock($handle, LOCK_EX | LOCK_NB), 'Unable to acquire an exclusive lock using the read-only stream wrapper.');
// Attempt to obtain a shared lock
$this->assertTrue(flock($handle, LOCK_SH | LOCK_NB), 'Able to acquire a shared lock using the read-only stream wrapper.');
// Attempt to release a shared lock
$this->assertTrue(flock($handle, LOCK_UN | LOCK_NB), 'Able to release a shared lock using the read-only stream wrapper.');
// Attempt to truncate the file
$this->assertFalse(@ftruncate($handle, 0), 'Unable to truncate using the read-only stream wrapper.');
// Attempt to write to the file
$this->assertFalse(@fwrite($handle, $this->randomMachineName()), 'Unable to write to file using the read-only stream wrapper.');
// Attempt to flush output to the file
$this->assertFalse(@fflush($handle), 'Unable to flush output to file using the read-only stream wrapper.');
// Attempt to close the stream. (Suppress errors, as fclose triggers fflush.)
$this->assertTrue(fclose($handle), 'Able to close file using the read_only stream wrapper.');
// Test the rename() function
$this->assertFalse(@rename($uri, $this->scheme . '://newname.txt'), 'Unable to rename files using the read-only stream wrapper.');
// Test the unlink() function
$this->assertTrue(@drupal_unlink($uri), 'Able to unlink file using read-only stream wrapper.');
$this->assertTrue(file_exists($filepath), 'Unlink File was not actually deleted.');
// Test the mkdir() function by attempting to create a directory.
$dirname = $this->randomMachineName();
$dir = $site_path . '/files/' . $dirname;
$readonlydir = $this->scheme . '://' . $dirname;
$this->assertFalse(@drupal_mkdir($readonlydir, 0775, 0), 'Unable to create directory with read-only stream wrapper.');
// Create a temporary directory for testing purposes
$this->assertTrue(drupal_mkdir($dir), 'Test directory created.');
// Test the rmdir() function by attempting to remove the directory.
$this->assertFalse(@drupal_rmdir($readonlydir), 'Unable to delete directory with read-only stream wrapper.');
// Remove the temporary directory.
drupal_rmdir($dir);
}
示例9: testSubscribers
/**
* Test the import subscriber.
*/
public function testSubscribers()
{
// Without this the config exporter breaks.
\Drupal::service('config.installer')->installDefaultConfig('module', 'config_devel');
$filename = vfsStream::url('public://' . static::CONFIGNAME . '.yml');
drupal_mkdir(vfsStream::url('public://exported'));
$exported_filename = vfsStream::url('public://exported/' . static::CONFIGNAME . '.yml');
\Drupal::configFactory()->getEditable('config_devel.settings')->set('auto_import', array(array('filename' => $filename, 'hash' => '')))->set('auto_export', array($exported_filename))->save();
$this->storage = \Drupal::service('config.storage');
$this->assertFalse($this->storage->exists(static::CONFIGNAME));
$subscriber = \Drupal::service('config_devel.auto_import_subscriber');
for ($i = 2; $i; $i--) {
$data['label'] = $this->randomString();
file_put_contents($filename, Yaml::encode($data));
// The import fires an export too.
$subscriber->autoImportConfig();
$this->doAssert($data, Yaml::decode(file_get_contents($exported_filename)));
}
}
示例10: setUpSyncForm
/**
* {@inheritdoc}
*/
protected function setUpSyncForm()
{
// Create a new sync directory.
drupal_mkdir($this->sync_dir);
// Extract the tarball into the sync directory.
$archiver = new ArchiveTar($this->tarball, 'gz');
$files = array();
foreach ($archiver->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver->extractList($files, $this->sync_dir);
// Change the user.settings::register so that we can test that
// standard_install() does not override it.
$sync = new FileStorage($this->sync_dir);
$user_settings = $sync->read('user.settings');
$user_settings['register'] = USER_REGISTER_ADMINISTRATORS_ONLY;
$sync->write('user.settings', $user_settings);
$this->drupalPostForm(NULL, array('sync_directory' => drupal_realpath($this->sync_dir)), 'Save and continue');
}
示例11: checkDirectory
/**
* Returns TRUE if the path is a directory or we can create one in that path.
*/
public static function checkDirectory($dir_path)
{
if (!is_dir($dir_path)) {
if (drupal_mkdir($dir_path, NULL, TRUE)) {
return TRUE;
} else {
// If the directory does not exists and cannot be created.
drupal_set_message(st('The directory %directory does not exist and could not be created.', array('%directory' => $dir_path)), 'error');
watchdog('file system', 'The directory %directory does not exist and could not be created.', array('%directory' => $dir_path), WATCHDOG_ERROR);
return FALSE;
}
} else {
if (is_writable($dir_path) || drupal_chmod($dir_path)) {
return TRUE;
}
watchdog('configuration', 'The current user does not have write permissions in the directory %dir.', array('%dir' => $dir_path), WATCHDOG_ERROR);
drupal_set_message(t('The current user does not have write permissions in the directory %dir.', array('%dir' => $dir_path)), 'error', FALSE);
}
return FALSE;
}
示例12: unl_reset_site_submit
function unl_reset_site_submit($form, &$form_state)
{
$nids = db_select('node', 'n')->fields('n', array('nid'))->execute()->fetchCol();
node_delete_multiple($nids);
variable_set('site_frontpage', 'node');
$mlids = db_select('menu_links', 'm')->fields('m', array('mlid'))->condition('m.menu_name', 'main-menu')->execute()->fetchCol();
foreach ($mlids as $mlid) {
menu_link_delete($mlid);
}
$home_link = array('link_path' => '<front>', 'link_title' => 'Home', 'menu_name' => 'main-menu', 'module' => 'menu');
menu_link_save($home_link);
$fids = db_select('file_managed', 'f')->fields('f', array('fid'))->execute()->fetchCol();
$files = file_load_multiple($fids);
foreach ($files as $file) {
file_delete($file);
}
$files_dir = DRUPAL_ROOT . '/' . conf_path() . '/files/';
$cmd = 'rm -rf ' . $files_dir . '*';
echo shell_exec($cmd);
drupal_mkdir('public://styles/');
variable_set('site_name', 'Site Name');
}
示例13: createDatabase
/**
* Overrides \Drupal\Core\Database\Connection::createDatabase().
*
* @param string $database
* The name of the database to create.
*
* @throws \Drupal\Core\Database\DatabaseNotFoundException
*/
public function createDatabase($database)
{
// Verify the database is writable.
$db_directory = new \SplFileInfo(dirname($database));
if (!$db_directory->isDir() && !drupal_mkdir($db_directory->getPathName(), 0755, TRUE)) {
throw new DatabaseNotFoundException('Unable to create database directory ' . $db_directory->getPathName());
}
}
示例14: createDirectory
/**
* Create a directory and assert it exists.
*
* @param $path
* Optional string with a directory path. If none is provided, a random
* name in the site's files directory will be used.
* @return
* The path to the directory.
*/
function createDirectory($path = NULL)
{
// A directory to operate on.
if (!isset($path)) {
$path = file_default_scheme() . '://' . $this->randomMachineName();
}
$this->assertTrue(drupal_mkdir($path) && is_dir($path), 'Directory was created successfully.');
return $path;
}
示例15: generateFile
/**
* Writes a file to the file system, creating its directory as needed.
*
* @param string $directory
* The extension's directory.
* @param array $file
* Array with the following keys:
* - 'filename': the name of the file.
* - 'subdirectory': any subdirectory of the file within the extension
* directory.
* - 'string': the contents of the file.
*
* @throws Exception
*/
protected function generateFile($directory, array $file)
{
if (!empty($file['subdirectory'])) {
$directory .= '/' . $file['subdirectory'];
}
if (!is_dir($directory)) {
if (drupal_mkdir($directory, NULL, TRUE) === FALSE) {
throw new \Exception($this->t('Failed to create directory @directory.', ['@directory' => $directory]));
}
}
if (file_put_contents($directory . '/' . $file['filename'], $file['string']) === FALSE) {
throw new \Exception($this->t('Failed to write file @filename.', ['@filename' => $file['filename']]));
}
}