本文整理汇总了PHP中sys_get_temp_dir函数的典型用法代码示例。如果您正苦于以下问题:PHP sys_get_temp_dir函数的具体用法?PHP sys_get_temp_dir怎么用?PHP sys_get_temp_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sys_get_temp_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dir_name
public function dir_name()
{
$path = ini_get("xhprof.output_dir");
$path = empty($path) ? sys_get_temp_dir() : $path;
return $path;
// return DATA_DIR."/xhprof/";
}
示例2: __construct
public function __construct($namespace = '', $defaultLifetime = 0, $directory = null)
{
parent::__construct('', $defaultLifetime);
if (!isset($directory[0])) {
$directory = sys_get_temp_dir() . '/symfony-cache';
}
if (isset($namespace[0])) {
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
throw new InvalidArgumentException(sprintf('FilesystemAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
}
$directory .= '/' . $namespace;
}
if (!file_exists($dir = $directory . '/.')) {
@mkdir($directory, 0777, true);
}
if (false === ($dir = realpath($dir))) {
throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
}
if (!is_writable($dir .= DIRECTORY_SEPARATOR)) {
throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory));
}
// On Windows the whole path is limited to 258 chars
if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
}
$this->directory = $dir;
}
示例3: testFromNonDirectoryWithNonExistingPath
public function testFromNonDirectoryWithNonExistingPath()
{
$directory = uniqid(sys_get_temp_dir() . 'non-existing', true);
$exception = InvalidDirectory::fromNonDirectory($directory);
self::assertInstanceOf(InvalidDirectory::class, $exception);
self::assertSame(sprintf('"%s" does not exists', $directory), $exception->getMessage());
}
示例4: testExecution
/**
* @dataProvider getFormat
* @runInSeparateProcess
*/
public function testExecution($format)
{
$tmpDir = sys_get_temp_dir() . '/sf_hello';
$filesystem = new Filesystem();
$filesystem->remove($tmpDir);
$filesystem->mkdirs($tmpDir);
chdir($tmpDir);
$tester = new CommandTester(new InitCommand());
$tester->execute(array('--name' => 'Hello' . $format, '--app-path' => 'hello' . $format, '--web-path' => 'web', '--src-path' => 'src', '--format' => $format));
// autoload
$content = file_get_contents($file = $tmpDir . '/src/autoload.php');
$content = str_replace("__DIR__.'/vendor", "'" . __DIR__ . "/../../../../src/vendor", $content);
file_put_contents($file, $content);
// Kernel
$class = 'Hello' . $format . 'Kernel';
$file = $tmpDir . '/hello' . $format . '/' . $class . '.php';
$this->assertTrue(file_exists($file));
$content = file_get_contents($file);
$content = str_replace("__DIR__.'/../src/vendor/Symfony/src/Symfony/Bundle'", "'" . __DIR__ . "/../../../../src/vendor/Symfony/src/Symfony/Bundle'", $content);
file_put_contents($file, $content);
require_once $file;
$kernel = new $class('dev', true);
$response = $kernel->handle(Request::create('/'));
$this->assertRegExp('/successfully/', $response->getContent());
$filesystem->remove($tmpDir);
}
示例5: processemail
public static function processemail($emailsrc, $pdfout, $coverfile = '')
{
$combfilelist = array();
# Process the email
$emailparts = Mail_mimeDecode::decode(array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => true, 'input' => file_get_contents($emailsrc), 'crlf' => "\r\n"));
# Process the cover if it exists
if ($coverfile !== '') {
$combfilelist[] = self::processpart(file_get_contents($coverfile), mime_content_type($coverfile));
}
# Process the parts
$combfilelist = array_merge($combfilelist, self::processparts($emailparts));
# Create an intermediate file to build the pdf
$tmppdffilename = sys_get_temp_dir() . '/e2p-' . (string) abs((int) (microtime(true) * 100000)) . '.pdf';
# Build the command to combine all of the intermediate files into one
$conbcom = str_replace(array_merge(array('INTFILE', 'COMBLIST'), array_keys(self::$driver_paths)), array_merge(array($tmppdffilename, implode(' ', $combfilelist)), array_values(self::$driver_paths)), self::$mime_drivers['gs']);
exec($conbcom);
# Remove the intermediate files
foreach ($combfilelist as $combfilename) {
unlink($combfilename);
}
# Write the intermediate file to the final destination
$intfileres = fopen($tmppdffilename, 'rb');
$outfileres = fopen($pdfout, 'ab');
while (!feof($intfileres)) {
fwrite($outfileres, fread($intfileres, 8192));
}
fclose($intfileres);
fclose($outfileres);
# Remove the intermediate file
unlink($tmppdffilename);
}
示例6: testSetPath
public function testSetPath()
{
$exporter = $this->getMockForAbstractClass(AbstractExporter::class);
$path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . sha1(time()) . DIRECTORY_SEPARATOR;
$exporter->setPath($path);
$this->assertEquals($path, $exporter->getPath());
}
示例7: setUp
public function setUp()
{
$this->numberOfPayloads = 5;
$this->tempDirectory = sys_get_temp_dir() . '/orphanage';
$this->realDirectory = sys_get_temp_dir() . '/storage';
$this->payloads = array();
$filesystem = new Filesystem();
$filesystem->mkdir($this->tempDirectory);
$filesystem->mkdir($this->realDirectory);
for ($i = 0; $i < $this->numberOfPayloads; $i++) {
// create temporary file
$file = tempnam(sys_get_temp_dir(), 'uploader');
$pointer = fopen($file, 'w+');
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
$this->payloads[] = new FilesystemFile(new UploadedFile($file, $i . 'grumpycat.jpeg', null, null, null, true));
}
// create underlying storage
$this->storage = new FilesystemStorage($this->realDirectory);
// is ignored anyways
$chunkStorage = new FilesystemChunkStorage('/tmp/');
// create orphanage
$session = new Session(new MockArraySessionStorage());
$session->start();
$config = array('directory' => $this->tempDirectory);
$this->orphanage = new FilesystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
}
示例8: setUp
public function setUp()
{
$this->tmpdir = sys_get_temp_dir() . '/' . uniqid('conveyor');
$this->projectdir = $this->tmpdir . '/project';
$this->reposdir = $this->tmpdir . '/repos';
$this->reposurl = 'file:///' . $this->reposdir;
$this->filesystem = new Filesystem();
$this->filesystem->mkdir($this->tmpdir);
$this->filesystem->mkdir($this->projectdir);
$svnadminbin = getenv('SVNADMIN_BIN') ? getenv('SVNADMIN_BIN') : '/usr/local/bin/svnadmin';
$svnbin = getenv('SVN_BIN') ? getenv('SVN_BIN') : '/usr/local/bin/svn';
if (!file_exists($svnadminbin)) {
$this->markTestSkipped(sprintf('%s not found', $svnadminbin));
}
if (!file_exists($svnbin)) {
$this->markTestSkipped(sprintf('%s not found', $svnbin));
}
$svnadmin = new Svnadmin($this->tmpdir, $svnadminbin);
$svnadmin->create(basename($this->reposdir));
$svn = new Svn($this->reposurl, new CliAdapter($svnbin, new Cli(), new CliParser()));
$svn->import(__DIR__ . '/../Test/Fixtures/skeleton/svn/trunk', '/', 'imported skeleton');
$svn->setHead(new Reference('2.1', Reference::TAG));
$svn->import(__DIR__ . '/../Test/Fixtures/skeleton/svn/tags/2.1', '/', 'imported skeleton');
$svn->setHead(new Reference('feature1', Reference::BRANCH));
$svn->import(__DIR__ . '/../Test/Fixtures/skeleton/svn/branches/feature1', '/', 'imported skeleton');
$content = file_get_contents(__DIR__ . '/../Test/Fixtures/conveyor.yml.twig');
$content = str_replace('{{ repository.url }}', $this->reposurl, $content);
file_put_contents($this->projectdir . '/conveyor.yml', $content);
chdir($this->projectdir);
}
示例9: assembleBook
public function assembleBook()
{
// implode all the contents to create the whole book
$book = $this->app->render('book.twig', array('items' => $this->app['publishing.items']));
$temp = tempnam(sys_get_temp_dir(), 'easybook_');
fputs(fopen($temp, 'w+'), $book);
// use PrinceXML to transform the HTML book into a PDF book
$prince = $this->app->get('prince');
$prince->setBaseURL($this->app['publishing.dir.contents'] . '/images');
// Prepare and add stylesheets before PDF conversion
if ($this->app->edition('include_styles')) {
$defaultStyles = tempnam(sys_get_temp_dir(), 'easybook_style_');
$this->app->renderThemeTemplate('style.css.twig', array('resources_dir' => $this->app['app.dir.resources'] . '/'), $defaultStyles);
$prince->addStyleSheet($defaultStyles);
}
// TODO: custom book styles could also be defined with Twig
$customCss = $this->app->getCustomTemplate('style.css');
if (file_exists($customCss)) {
$prince->addStyleSheet($customCss);
}
// TODO: the name of the book file (book.pdf) must be configurable
$errorMessages = array();
$prince->convert_file_to_file($temp, $this->app['publishing.dir.output'] . '/book.pdf', $errorMessages);
// show PDF conversion errors
if (count($errorMessages) > 0) {
foreach ($errorMessages as $message) {
echo $message[0] . ': ' . $message[2] . ' (' . $message[1] . ')' . "\n";
}
}
}
示例10: setUp
public function setUp()
{
parent::setUp();
$this->originalFile = __DIR__ . '/files/testimage.gif';
$this->compressedFile = $temp_file = sys_get_temp_dir() . '/php_image_optimizer.gif';
copy($this->originalFile, $this->compressedFile);
}
示例11: getZippedFile
private static function getZippedFile($filename) {
if(!self::zipModuleLoaded()) {
throw new WURFL_WURFLException("The Zip extension is not loaded. Load the extension or use the flat wurfl.xml file");
}
$tmpDir = sys_get_temp_dir();
$zip = new ZipArchive();
if ($zip->open($filename)!==TRUE) {
exit("cannot open <$filename>\n");
}
$zippedFile = $zip->statIndex(0);
$wurflFile = $zippedFile['name'];
//$wurflFile = md5(uniqid(rand(), true));
//$zip->extractTo($tmpDir, $wurflFile);
$zip->extractTo($tmpDir);
$zip->close();
return $tmpDir . '/' .$wurflFile;
}
示例12: testDetectTypeFromFileCannotOpen
/**
* @expectedException XML_XRD_Loader_Exception
* @expectedExceptionMessage Cannot open file to determine type
*/
public function testDetectTypeFromFileCannotOpen()
{
$file = tempnam(sys_get_temp_dir(), 'xml_xrd-unittests');
$this->cleanupList[] = $file;
chmod($file, '0000');
@$this->loader->detectTypeFromFile($file);
}
示例13: tempFilename
protected function tempFilename()
{
$temp_dir = is_null($this->temp_dir) ? sys_get_temp_dir() : $this->temp_dir;
$filename = tempnam($temp_dir, "xlsx_writer_");
$this->temp_files[] = $filename;
return $filename;
}
示例14: php_sys_get_temp_dir
/**
* NOTE: This function is incomplete, the fallback is to '/tmp' which targets Unix-like.
*
* @return string
*/
function php_sys_get_temp_dir()
{
// (PHP 5 >= 5.2.1)
if (function_exists('sys_get_temp_dir')) {
return sys_get_temp_dir();
}
// (PHP 4 >= 4.3.0, PHP 5)
if (function_exists('stream_get_meta_data')) {
$handle = tmpfile();
// (PHP 4, PHP 5)
$meta = stream_get_meta_data($handle);
// (PHP 5 >= 5.1.0)
if (isset($meta['uri'])) {
return dirname($meta['uri']);
}
}
// emulate PHP 4 <= 4.0.6 tempnam() behavior, fragile
foreach (array('TMPDIR', 'TMP') as $key) {
if (isset($_ENV[$key])) {
return $_ENV[$key];
}
}
// fallback for Unix-like (php_shell specifically)
return '/tmp';
}
示例15: generate
public function generate()
{
$tempPath = sys_get_temp_dir() . '/';
// FastCGI fix for Windows machines, where temp path is not available to
// PHP, and defaults to the unwritable system directory. If the temp
// path is pointing to the system directory, shift to the 'TEMP'
// sub-folder, which should also exist, but actually be writable.
if (IS_WIN && $tempPath == getenv("SystemRoot") . '/') {
$tempPath = getenv("SystemRoot") . '/TEMP/';
}
$keyFile = $tempPath . md5(microtime(true));
if (!is_dir($tempPath)) {
mkdir($tempPath);
}
$return = array();
if ($this->canGenerateKeys()) {
shell_exec('ssh-keygen -q -t rsa -b 2048 -f ' . $keyFile . ' -N "" -C "deploy@phpci"');
$pub = file_get_contents($keyFile . '.pub');
$prv = file_get_contents($keyFile);
if (empty($pub)) {
$pub = '';
}
if (empty($prv)) {
$prv = '';
}
$return = array('private_key' => $prv, 'public_key' => $pub);
}
return $return;
}