本文整理汇总了PHP中file_directory_temp函数的典型用法代码示例。如果您正苦于以下问题:PHP file_directory_temp函数的具体用法?PHP file_directory_temp怎么用?PHP file_directory_temp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_directory_temp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* {@inheritdoc}
*/
public function generate(array $packages = array(), FeaturesBundleInterface $bundle = NULL)
{
$filename = isset($bundle) && $bundle->isProfile() ? $bundle->getProfileName() : 'generated_features';
// If no packages were specified, get all packages.
if (empty($packages)) {
$packages = $this->featuresManager->getPackages();
} elseif (count($packages) == 1) {
// Single package export, so name tar archive by package name.
$filename = current($packages)['machine_name'];
}
$return = [];
$this->archiveName = $filename . '.tar.gz';
$archive_name = file_directory_temp() . '/' . $this->archiveName;
if (file_exists($archive_name)) {
file_unmanaged_delete($archive_name);
}
$archiver = new ArchiveTar($archive_name);
// Add package files.
foreach ($packages as $package) {
if (count($packages) == 1) {
// Single module export, so don't generate entire modules dir structure.
$package['directory'] = $package['machine_name'];
}
$this->generatePackage($return, $package, $archiver);
}
return $return;
}
示例2: testExport
/**
* Tests export of configuration.
*/
function testExport()
{
// Verify the export page with export submit button is available.
$this->drupalGet('admin/config/development/configuration/full/export');
$this->assertFieldById('edit-submit', t('Export'));
// Submit the export form and verify response.
$this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
$this->assertResponse(200, 'User can access the download callback.');
// Get the archived binary file provided to user for download.
$archive_data = $this->drupalGetContent();
// Temporarily save the archive file.
$uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz');
// Extract the archive and verify it's not empty.
$file_path = file_directory_temp() . '/' . file_uri_target($uri);
$archiver = new Tar($file_path);
$archive_contents = $archiver->listContents();
$this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
// Prepare the list of config files from active storage, see
// \Drupal\config\Controller\ConfigController::downloadExport().
$storage_active = $this->container->get('config.storage');
$config_files = array();
foreach ($storage_active->listAll() as $config_name) {
$config_files[] = $config_name . '.yml';
}
// Assert that the downloaded archive file contents are the same as the test
// site active store.
$this->assertIdentical($archive_contents, $config_files);
// Ensure the test configuration override is in effect but was not exported.
$this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo');
$archiver->extract(file_directory_temp(), array('system.maintenance.yml'));
$file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml');
$exported = Yaml::decode($file_contents);
$this->assertNotIdentical($exported['message'], 'Foo');
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$messageHelper = $this->getHelperSet()->get('message');
$directory = $input->getArgument('directory');
if (!$directory) {
$config = $this->getConfigFactory()->get('system.file');
$directory = $config->get('path.temporary') ?: file_directory_temp();
$directory .= '/' . CONFIG_STAGING_DIRECTORY;
}
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}
$config_export_file = $directory . '/config.tar.gz';
file_unmanaged_delete($config_export_file);
try {
$archiver = new ArchiveTar($config_export_file, 'gz');
$this->configManager = $this->getConfigManager();
// Get raw configuration data without overrides.
foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
$archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
}
$this->targetStorage = $this->getConfigStorage();
// Get all override data from the remaining collections.
foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
$collection_storage = $this->targetStorage->createCollection($collection);
foreach ($collection_storage->listAll() as $name) {
$archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
}
}
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
$messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory'), $config_export_file));
}
示例4: getHooksDirectorySetting
/**
* Set the hooks directory.
*/
function getHooksDirectorySetting()
{
// Set the folder for the hooks. This contains a prepared file for the tests
// to use.
// By some magic this appears to be safe to use with DrupalUnitTestCase.
$directory = file_directory_temp() . '/module_builder_hook_definitions/' . $this->major_version;
$this->hooks_directory = $directory;
}
示例5: testExportArchive
public function testExportArchive()
{
$filename = file_directory_temp() . '/' . self::PACKAGE_NAME . '.tar.gz';
if (file_exists($filename)) {
unlink($filename);
}
$this->assertFalse(file_exists($filename), 'Archive file already exists.');
$this->generator->generatePackages('archive', [self::PACKAGE_NAME], $this->assigner->getBundle());
$this->assertTrue(file_exists($filename), 'Archive file was not generated.');
}
示例6: nodeImportCreateFile
/**
* Create a file with the specified data.
*
* @param $data
* Twodimensional array.
*
* @param $file_options
* Array with record separator, etc.
*
* @return
* String. Path to file (in temporary directory).
*/
public function nodeImportCreateFile($data, $file_options = array())
{
module_load_include('inc', 'node_import');
$path = file_create_filename($this->randomName() . '.csv', file_directory_temp());
$fp = fopen($path, 'w');
foreach ($data as $row) {
$s = node_import_write_to_string($row, $file_options);
fputs($fp, $s);
}
fclose($fp);
return $path;
}
示例7: testExport
/**
* Tests export of configuration.
*/
function testExport()
{
// Verify the export page with export submit button is available.
$this->drupalGet('admin/config/development/configuration/full/export');
$this->assertFieldById('edit-submit', t('Export'));
// Submit the export form and verify response.
$this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
$this->assertResponse(200, 'User can access the download callback.');
// Test if header contains file name with hostname and timestamp.
$request = \Drupal::request();
$hostname = str_replace('.', '-', $request->getHttpHost());
$header_content_disposition = $this->drupalGetHeader('content-disposition');
$header_match = (bool) preg_match('/attachment; filename="config-' . preg_quote($hostname) . '-\\d{4}-\\d{2}-\\d{2}-\\d{2}-\\d{2}\\.tar\\.gz"/', $header_content_disposition);
$this->assertTrue($header_match, "Header with filename matches the expected format.");
// Get the archived binary file provided to user for download.
$archive_data = $this->getRawContent();
// Temporarily save the archive file.
$uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz');
// Extract the archive and verify it's not empty.
$file_path = file_directory_temp() . '/' . file_uri_target($uri);
$archiver = new Tar($file_path);
$archive_contents = $archiver->listContents();
$this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
// Prepare the list of config files from active storage, see
// \Drupal\config\Controller\ConfigController::downloadExport().
$storage_active = $this->container->get('config.storage');
$config_files = array();
foreach ($storage_active->listAll() as $config_name) {
$config_files[] = $config_name . '.yml';
}
// Assert that the downloaded archive file contents are the same as the test
// site active store.
$this->assertIdentical($archive_contents, $config_files);
// Ensure the test configuration override is in effect but was not exported.
$this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo');
$archiver->extract(file_directory_temp(), array('system.maintenance.yml'));
$file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml');
$exported = Yaml::decode($file_contents);
$this->assertNotIdentical($exported['message'], 'Foo');
// Check the single export form doesn't have "form-required" elements.
$this->drupalGet('admin/config/development/configuration/single/export');
$this->assertNoRaw('js-form-required form-required', 'No form required fields are found.');
// Ensure the temporary file is not available to users without the
// permission.
$this->drupalLogout();
$this->drupalGet('system/temporary', ['query' => ['file' => 'config.tar.gz']]);
$this->assertResponse(403);
}
示例8: testGeneratorWithBundle
/**
* @covers \Drupal\features\FeaturesGenerator::setPackageBundleNames
*/
public function testGeneratorWithBundle()
{
$filename = file_directory_temp() . '/giraffe_' . self::PACKAGE_NAME . '.tar.gz';
if (file_exists($filename)) {
unlink($filename);
}
$this->assertFalse(file_exists($filename), 'Archive file already exists.');
$bundle = FeaturesBundle::create(['machine_name' => 'giraffe']);
$this->generator->generatePackages('archive', [self::PACKAGE_NAME], $bundle);
$package = $this->featuresManager->getPackage(self::PACKAGE_NAME);
$this->assertNull($package);
$package = $this->featuresManager->getPackage('giraffe_' . self::PACKAGE_NAME);
$this->assertEquals('giraffe_' . self::PACKAGE_NAME, $package->getMachineName());
$this->assertEquals('giraffe', $package->getBundle());
$this->assertTrue(file_exists($filename), 'Archive file was not generated.');
}
示例9: downloadExport
/**
* Downloads a tarball of the site configuration.
*/
public function downloadExport()
{
file_unmanaged_delete(file_directory_temp() . '/config.tar.gz');
$archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz');
// Get raw configuration data without overrides.
foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
$archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
}
// Get all override data from the remaining collections.
foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
$collection_storage = $this->targetStorage->createCollection($collection);
foreach ($collection_storage->listAll() as $name) {
$archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
}
}
$request = new Request(array('file' => 'config.tar.gz'));
return $this->fileDownloadController->download($request, 'temporary');
}
示例10: _fetch
/**
* (non-PHPdoc)
* @see Yamm_FileFetcher::_fetch()
*/
public function _fetch($filepath)
{
$source_url = yamm_api_clean_url($this->_server->getUrl()) . $filepath;
// Get file contents.
if ($data = file_get_contents($source_url, FILE_BINARY)) {
// Get a new temporary file name, for file creation.
$tmp = file_directory_temp() . '/' . uniqid('yamm-');
// If we go some content, return new file path as data.
if (file_put_contents($tmp, $data) > 0) {
// Free up some memory after copy.
unset($data);
return $tmp;
} else {
throw new Yamm_FileFetcher_CouldNotFetchException("Unable to save " . $source_url . " downloaded file as temporary file");
}
} else {
throw new Yamm_FileFetcher_CouldNotFetchException("Unable to download file " . $source_url);
}
}
示例11: resizeimage_wrapper_filecache
function resizeimage_wrapper_filecache()
{
global $bgcachexpire;
$bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
#echo $bgcacheid;
#echo '. 0.... ';
# Tested that both relative (eg sites/all/files/cache) and absolute (eg /home/data/tmp) tmp path settings work OK here.
$cachetemp = variable_get('brilliant_gallery_pcache', file_directory_temp());
#$cachedfile = file_directory_temp() .'/'. $bgcacheid;
$cachedfile = $cachetemp . '/' . $bgcacheid;
#$cachedfile = realpath(file_directory_temp() . '/' . $bgcacheid);
#echo file_directory_temp() . '/' . $bgcacheid;
#echo " .... ";
#echo $cachedfile;
# See http://drupal.org/node/194923
$lastchanged = file_exists($cachedfile) ? filemtime($cachedfile) : false;
if ($lastchanged === false or time() - $lastchanged > $bgcachexpire) {
#echo '. 1.... ';
# Cache file does not exist or is too old.
$my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh']);
# Now put $my_data to cache!
$fh = fopen($cachedfile, "w+");
fwrite($fh, $my_data);
fclose($fh);
#test
/*
$my_data_t = unserialize( $my_data );
$fh = fopen( $cachedfile . '_2', "w+" );
fwrite( $fh, $my_data_t[1] );
fclose( $fh );
*/
$my_data = unserialize($my_data);
} else {
#echo '. 2.... ';
# Cache file exists.
$my_data = unserialize(file_get_contents($cachedfile));
}
return $my_data;
}
示例12: downloadDocument
/**
* Downloads the translated document for the specified document and language.
*
* @param int $document_id
* The Lingotek document ID that should be downloaded.
* @param string $language_lingotek
* A Lingotek language/locale code.
*
* @return mixed
* On success, a SimpleXMLElement object representing the translated document. FALSE on failure.
*
*/
public function downloadDocument($document_id, $language_lingotek)
{
$document = FALSE;
$params = array('documentId' => $document_id, 'targetLanguage' => $language_lingotek);
if ($results = $this->request('downloadDocument', $params)) {
try {
// TODO: This is borrowed from the now-deprecated LingotekSession::download()
// and could use refactoring.
$tmpFile = tempnam(file_directory_temp(), 'lingotek');
$fp = fopen($tmpFile, 'w');
fwrite($fp, $results);
fclose($fp);
$text = '';
$file = FALSE;
// downloadDocument returns zip-encoded data.
$zip = new ZipArchive();
$zip->open($tmpFile);
$name = $zip->getNameIndex(0);
$file = $zip->getStream($name);
if ($file) {
while (!feof($file)) {
$text .= fread($file, 2);
}
fclose($file);
}
unlink($tmpFile);
$document = new SimpleXMLElement($text);
} catch (Exception $e) {
LingotekLog::error('Unable to parse downloaded document. Error: @error. Text: !xml.', array('!xml' => $text, '@error' => $e->getMessage()));
}
}
return $document;
}
示例13: __get
/**
* BC: Automatically resolve former KernelTestBase class properties.
*
* Test authors should follow the provided instructions and adjust their tests
* accordingly.
*
* @deprecated in Drupal 8.0.x, will be removed before Drupal 8.2.0.
*/
public function __get($name)
{
if (in_array($name, array('public_files_directory', 'private_files_directory', 'temp_files_directory', 'translation_files_directory'))) {
// @comment it in again.
trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use the regular API method to retrieve it instead (e.g., Settings).", $name), E_USER_DEPRECATED);
switch ($name) {
case 'public_files_directory':
return Settings::get('file_public_path', \Drupal::service('site.path') . '/files');
case 'private_files_directory':
return $this->container->get('config.factory')->get('system.file')->get('path.private');
case 'temp_files_directory':
return file_directory_temp();
case 'translation_files_directory':
return Settings::get('file_public_path', \Drupal::service('site.path') . '/translations');
}
}
if ($name === 'configDirectories') {
trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use config_get_config_directory() directly instead.", $name), E_USER_DEPRECATED);
return array(CONFIG_SYNC_DIRECTORY => config_get_config_directory(CONFIG_SYNC_DIRECTORY));
}
$denied = array('testId', 'timeLimit', 'results', 'assertions', 'skipClasses', 'verbose', 'verboseId', 'verboseClassName', 'verboseDirectory', 'verboseDirectoryUrl', 'dieOnFail', 'kernel', 'generatedTestFiles', 'keyValueFactory');
if (in_array($name, $denied) || strpos($name, 'original') === 0) {
throw new \RuntimeException(sprintf('TestBase::$%s property no longer exists', $name));
}
}
示例14: hook_file_transfer_alter
/**
* Make changes to a file before it is downloaded by the customer.
*
* Stores, either for customization, copy protection or other reasons, might want
* to send customized downloads to customers. This hook will allow this to happen.
* Before a file is opened to be transfered to a customer, this hook will be called
* to make any altercations to the file that will be used to transfer the download
* to the customer. This, in effect, will allow a developer to create a new,
* personalized, file that will get transfered to a customer.
*
* @param $file_user
* The file_user object (i.e. an object containing a row from the uc_file_users
* table) that corresponds with the user download being accessed.
* @param $ip
* The IP address from which the customer is downloading the file
* @param $fid
* The file id of the file being transfered
* @param $file
* The file path of the file to be transfered
* @return
* The path of the new file to transfer to customer.
*/
function hook_file_transfer_alter($file_user, $ip, $fid, $file)
{
$file_data = file_get_contents($file) . " [insert personalized data]";
//for large files this might be too memory intensive
$new_file = tempnam(file_directory_temp(), 'tmp');
file_put_contents($new_file, $file_data);
return $new_file;
}
示例15: install_main
//.........这里部分代码省略.........
module_list(TRUE, FALSE, FALSE, $module_list);
drupal_load('module', 'system');
drupal_load('module', 'filter');
// Load the cache infrastructure using a "fake" cache implementation that
// does not attempt to write to the database. We need this during the initial
// part of the installer because the database is not available yet. We
// continue to use it even when the database does become available, in order
// to preserve consistency between interactive and command-line installations
// (the latter complete in one page request and therefore are forced to
// continue using the cache implementation they started with) and also
// because any data put in the cache during the installer is inherently
// suspect, due to the fact that Drupal is not fully set up yet.
require_once DRUPAL_ROOT . '/includes/cache-install.inc';
$conf['cache_inc'] = './includes/cache-install.inc';
// Install profile chosen, set the global immediately.
// This needs to be done before the theme cache gets
// initialized in drupal_maintenance_theme().
if (!empty($_GET['profile'])) {
$profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']);
}
// Set up theme system for the maintenance page.
drupal_maintenance_theme();
// Check existing settings.php.
$verify = install_verify_settings();
if ($verify) {
// Establish a connection to the database.
require_once DRUPAL_ROOT . '/includes/database.inc';
db_set_active();
// Check if Drupal is installed.
$task = install_verify_drupal();
if ($task == 'done') {
install_already_done_error();
}
} else {
$task = NULL;
}
// No profile was passed in GET, ask the user.
if (empty($_GET['profile'])) {
if ($profile = install_select_profile()) {
install_goto("install.php?profile={$profile}");
} else {
install_no_profile_error();
}
}
// Load the profile.
require_once DRUPAL_ROOT . "/profiles/{$profile}/{$profile}.profile";
// Locale selection
if (!empty($_GET['locale'])) {
$install_locale = preg_replace('/[^a-zA-Z_0-9\\-]/', '', $_GET['locale']);
} elseif (($install_locale = install_select_locale($profile)) !== FALSE) {
install_goto("install.php?profile={$profile}&locale={$install_locale}");
}
// Tasks come after the database is set up
if (!$task) {
global $db_url;
if (!$verify && !empty($db_url)) {
// Do not install over a configured settings.php.
install_already_done_error();
}
// Check the installation requirements for Drupal and this profile.
install_check_requirements($profile, $verify);
// Verify existence of all required modules.
$modules = drupal_verify_profile($profile, $install_locale);
// If any error messages are set now, it means a requirement problem.
$messages = drupal_set_message();
if (!empty($messages['error'])) {
install_task_list('requirements');
drupal_set_title(st('Requirements problem'));
print theme('install_page', '');
exit;
}
// Change the settings.php information if verification failed earlier.
// Note: will trigger a redirect if database credentials change.
if (!$verify) {
install_change_settings($profile, $install_locale);
}
// The default lock implementation uses a database table,
// so we cannot use it for install, but we still need
// the API functions available.
require_once './includes/lock-install.inc';
$conf['lock_inc'] = './includes/lock-install.inc';
lock_init();
// Install system.module.
drupal_install_system();
// Ensure that all of Drupal's standard directories have appropriate
// .htaccess files. These directories will have already been created by
// this point in the installer, since Drupal creates them during the
// install_check_requirements() task. Note that we cannot create them any
// earlier than this, since the code below relies on system.module in order
// to work.
file_create_htaccess(file_directory_path());
file_create_htaccess(file_directory_temp());
// Save the list of other modules to install for the 'profile-install'
// task. variable_set() can be used now that system.module is installed
// and drupal is bootstrapped.
variable_set('install_profile_modules', array_diff($modules, array('system')));
}
// The database is set up, turn to further tasks.
install_tasks($profile, $task);
}