当前位置: 首页>>代码示例>>PHP>>正文


PHP tempnam函数代码示例

本文整理汇总了PHP中tempnam函数的典型用法代码示例。如果您正苦于以下问题:PHP tempnam函数的具体用法?PHP tempnam怎么用?PHP tempnam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了tempnam函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructor
  *
  * @param array $data the form data as name => value
  * @param string|null $suffix the optional suffix for the tmp file
  * @param string|null $suffix the optional prefix for the tmp file. If null 'php_tmpfile_' is used.
  * @param string|null $directory directory where the file should be created. Autodetected if not provided.
  * @param string|null $encoding of the data. Default is 'UTF-8'.
  */
 public function __construct($data, $suffix = null, $prefix = null, $directory = null, $encoding = 'UTF-8')
 {
     if ($directory === null) {
         $directory = self::getTempDir();
     }
     $suffix = '.fdf';
     $prefix = 'php_pdftk_fdf_';
     $this->_fileName = tempnam($directory, $prefix);
     $newName = $this->_fileName . $suffix;
     rename($this->_fileName, $newName);
     $this->_fileName = $newName;
     $fields = '';
     foreach ($data as $key => $value) {
         // Create UTF-16BE string encode as ASCII hex
         // See http://blog.tremily.us/posts/PDF_forms/
         $utf16Value = mb_convert_encoding($value, 'UTF-16BE', $encoding);
         /* Also create UTF-16BE encoded key, this allows field names containing
          * german umlauts and most likely many other "special" characters.
          * See issue #17 (https://github.com/mikehaertl/php-pdftk/issues/17)
          */
         $utf16Key = mb_convert_encoding($key, 'UTF-16BE', $encoding);
         // Escape parenthesis
         $utf16Value = strtr($utf16Value, array('(' => '\\(', ')' => '\\)'));
         $fields .= "<</T(" . chr(0xfe) . chr(0xff) . $utf16Key . ")/V(" . chr(0xfe) . chr(0xff) . $utf16Value . ")>>\n";
     }
     // Use fwrite, since file_put_contents() messes around with character encoding
     $fp = fopen($this->_fileName, 'w');
     fwrite($fp, self::FDF_HEADER);
     fwrite($fp, $fields);
     fwrite($fp, self::FDF_FOOTER);
     fclose($fp);
 }
开发者ID:aviddv1,项目名称:php-pdftk,代码行数:41,代码来源:FdfFile.php

示例2: __construct

 function __construct($loginname, $membername, $password)
 {
     $this->cookie_file = tempnam('./tmp', 'HUNTERON');
     $this->loginname = $loginname;
     $this->membername = $membername;
     $this->password = $password;
 }
开发者ID:RenzcPHP,项目名称:spider,代码行数:7,代码来源:hunteron.php

示例3: writeFile

 /**
  * Writes file in a save way to disk
  *
  * @param  string  $_filepath complete filepath
  * @param  string  $_contents file content
  * @return boolean true
  */
 public static function writeFile($_filepath, $_contents, $smarty)
 {
     $old_umask = umask(0);
     $_dirpath = dirname($_filepath);
     // if subdirs, create dir structure
     if ($_dirpath !== '.' && !file_exists($_dirpath)) {
         mkdir($_dirpath, $smarty->_dir_perms, true);
     }
     // write to tmp file, then move to overt file lock race condition
     $_tmp_file = tempnam($_dirpath, 'wrt');
     if (!($fd = @fopen($_tmp_file, 'wb'))) {
         $_tmp_file = $_dirpath . DS . uniqid('wrt');
         if (!($fd = @fopen($_tmp_file, 'wb'))) {
             throw new SmartyException("unable to write file {$_tmp_file}");
             return false;
         }
     }
     fwrite($fd, $_contents);
     fclose($fd);
     // remove original file
     if (file_exists($_filepath)) {
         @unlink($_filepath);
     }
     // rename tmp file
     rename($_tmp_file, $_filepath);
     // set file permissions
     chmod($_filepath, $smarty->_file_perms);
     umask($old_umask);
     return true;
 }
开发者ID:kiang,项目名称:olc_baker,代码行数:37,代码来源:smarty_internal_write_file.php

示例4: 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";
         }
     }
 }
开发者ID:raulfraile,项目名称:easybook,代码行数:30,代码来源:PdfPublisher.php

示例5: XLSReporte

 function XLSReporte($mSQL = '')
 {
     $this->ccols = 0;
     if (!empty($mSQL)) {
         $CI =& get_instance();
         $this->DBquery = $CI->db->query($mSQL);
         $data = $this->DBquery->field_data();
         foreach ($data as $field) {
             $this->DBfieldsName[] = $field->name;
             $this->DBfieldsType[$field->name] = $field->type;
             $this->DBfieldsMax_lengt[$field->name] = $field->max_length;
         }
     }
     $this->fname = tempnam("/tmp", "reporte.xls");
     $this->workbook = new writeexcel_workbookbig($this->fname);
     $this->worksheet = $this->workbook->addworksheet();
     //estilos encabezados
     $this->h1 =& $this->workbook->addformat(array('bold' => 1, 'color' => 'black', 'size' => 18, 'merge' => 1));
     $this->h2 =& $this->workbook->addformat(array('bold' => 1, 'color' => 'black', 'size' => 16, 'merge' => 1));
     $this->h3 =& $this->workbook->addformat(array('bold' => 1, 'color' => 'black', 'size' => 12, 'merge' => 1, 'align' => 'left'));
     $this->h4 =& $this->workbook->addformat(array('bold' => 1, 'color' => 'black', 'size' => 8, 'merge' => 0, 'align' => 'left'));
     $this->h5 =& $this->workbook->addformat(array('bold' => 1, 'color' => 'black', 'size' => 6, 'merge' => 0));
     $this->t1 =& $this->workbook->addformat(array("bold" => 1, "size" => 9, "merge" => 0, "fg_color" => 0x37));
     $this->t2 =& $this->workbook->addformat(array("bold" => 1, "size" => 8, "merge" => 0, "fg_color" => 0x2f));
 }
开发者ID:codethics,项目名称:proteoerp,代码行数:25,代码来源:XLSReporte.php

示例6: data

 /**
  * {@inheritdoc}
  */
 public function data(ServerRequestInterface $request, Document $document)
 {
     $this->assertAdmin($request->getAttribute('actor'));
     $file = array_get($request->getUploadedFiles(), 'favicon');
     $tmpFile = tempnam($this->app->storagePath() . '/tmp', 'favicon');
     $file->moveTo($tmpFile);
     $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
     if ($extension !== 'ico') {
         $manager = new ImageManager();
         $encodedImage = $manager->make($tmpFile)->resize(64, 64, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->encode('png');
         file_put_contents($tmpFile, $encodedImage);
         $extension = 'png';
     }
     $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath() . '/assets'))]);
     if (($path = $this->settings->get('favicon_path')) && $mount->has($file = "target://{$path}")) {
         $mount->delete($file);
     }
     $uploadName = 'favicon-' . Str::lower(Str::quickRandom(8)) . '.' . $extension;
     $mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
     $this->settings->set('favicon_path', $uploadName);
     return parent::data($request, $document);
 }
开发者ID:flarum,项目名称:core,代码行数:28,代码来源:UploadFaviconController.php

示例7: testCompile

 public function testCompile()
 {
     $compression = 'none';
     $namespaced = 'yes';
     $selection = array('_phpjs_shared_bc' => true, 'array_shift' => true, 'bcadd' => true);
     $options = array('pref_title' => 'test.php', 'compression' => $compression, 'namespaced' => $namespaced);
     #$selection = array_flip(array_keys($this->PHPJS->Functions));
     // Set selection
     $this->PHPJS->clearSelection();
     foreach ($selection as $functionName => $bool) {
         $this->PHPJS->addToSelection('function::' . $functionName);
     }
     #pr($this->PHPJS->getSelection());
     // Set flags
     $flags = 0;
     if ($options['namespaced'] == 'yes') {
         $flags = $flags | PHPJS_Library_Compiler::COMPILE_NAMESPACED;
     } elseif ($options['namespaced'] == 'commonjs') {
         $flags = $flags | PHPJS_Library_Compiler::COMPILE_COMMONJS;
     }
     if ($options['compression'] == 'minified') {
         $flags = $flags | PHPJS_Library_Compiler::COMPILE_MINFIED;
     }
     if ($options['compression'] == 'packed') {
         $flags = $flags | PHPJS_Library_Compiler::COMPILE_PACKED;
     }
     $code = $this->PHPJS->compile($flags, 't' . date("H:i:s"));
     $tmp = tempnam('/tmp', 'phpjstest') . '.js';
     echo "You could run: \n  rhino -debug " . $tmp . "\n";
     file_put_contents($tmp, $code);
 }
开发者ID:wuthering-bytes,项目名称:thrak,代码行数:31,代码来源:PHPJS_LibraryCompileTest.php

示例8: write_file

 public static function write_file($filename, $content)
 {
     /*
     Atomically writes, or overwrites, the given content to a file.
     
     Atomic file writes are required for cache updates, and when
     writing compiled templates, to avoid race conditions.
     */
     $temp = tempnam(OUTLINE_CACHE_PATH, 'temp');
     if (!($f = @fopen($temp, 'wb'))) {
         $temp = OUTLINE_CACHE_PATH . DIRECTORY_SEPARATOR . uniqid('temp');
         if (!($f = @fopen($temp, 'wb'))) {
             trigger_error("OutlineUtil::write_file() : error writing temporary file '{$temp}'", E_USER_WARNING);
             return false;
         }
     }
     fwrite($f, $content);
     fclose($f);
     if (!@rename($temp, $filename)) {
         @unlink($filename);
         @rename($temp, $filename);
     }
     @chmod($filename, OUTLINE_FILE_MODE);
     return true;
 }
开发者ID:alopix,项目名称:aoxPages,代码行数:25,代码来源:util.php

示例9: 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);
 }
开发者ID:pear,项目名称:xml_xrd,代码行数:11,代码来源:LoaderTest.php

示例10: 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;
 }
开发者ID:mk-j,项目名称:php_xlsxwriter,代码行数:7,代码来源:xlsxwriter.class.php

示例11: testCrossCheck

 /**
  * @dataProvider crossCheckLoadersDumpers
  */
 public function testCrossCheck($fixture, $type)
 {
     $loaderClass = 'Symfony\\Components\\DependencyInjection\\Loader\\' . ucfirst($type) . 'FileLoader';
     $dumperClass = 'Symfony\\Components\\DependencyInjection\\Dumper\\' . ucfirst($type) . 'Dumper';
     $tmp = tempnam('sf_service_container', 'sf');
     file_put_contents($tmp, file_get_contents(self::$fixturesPath . '/' . $type . '/' . $fixture));
     $container1 = new ContainerBuilder();
     $loader1 = new $loaderClass($container1);
     $loader1->load($tmp);
     $dumper = new $dumperClass($container1);
     file_put_contents($tmp, $dumper->dump());
     $container2 = new ContainerBuilder();
     $loader2 = new $loaderClass($container2);
     $loader2->load($tmp);
     unlink($tmp);
     $this->assertEquals($container2->getAliases(), $container1->getAliases(), 'loading a dump from a previously loaded container returns the same container');
     $this->assertEquals($container2->getDefinitions(), $container1->getDefinitions(), 'loading a dump from a previously loaded container returns the same container');
     $this->assertEquals($container2->getParameterBag()->all(), $container1->getParameterBag()->all(), '->getParameterBag() returns the same value for both containers');
     $this->assertEquals(serialize($container2), serialize($container1), 'loading a dump from a previously loaded container returns the same container');
     $services1 = array();
     foreach ($container1 as $id => $service) {
         $services1[$id] = serialize($service);
     }
     $services2 = array();
     foreach ($container2 as $id => $service) {
         $services2[$id] = serialize($service);
     }
     unset($services1['service_container'], $services2['service_container']);
     $this->assertEquals($services2, $services1, 'Iterator on the containers returns the same services');
 }
开发者ID:khalid05,项目名称:symfony,代码行数:33,代码来源:CrossCheckTest.php

示例12: smarty_core_write_file

/**
 * write out a file to disk
 *
 * @param string $filename
 * @param string $contents
 * @param boolean $create_dirs
 * @return boolean
 */
function smarty_core_write_file($params, &$smarty)
{
    $_dirname = dirname($params['filename']);
    if ($params['create_dirs']) {
        $_params = array('dir' => $_dirname);
        require_once SMARTY_CORE_DIR . 'core.create_dir_structure.php';
        smarty_core_create_dir_structure($_params, $smarty);
    }
    // write to tmp file, then rename it to avoid
    // file locking race condition
    $_tmp_file = tempnam($_dirname, 'wrt');
    if (!($fd = @fopen($_tmp_file, 'wb'))) {
        $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
        if (!($fd = @fopen($_tmp_file, 'wb'))) {
            $smarty->trigger_error("problem writing temporary file '{$_tmp_file}'");
            return false;
        }
    }
    fwrite($fd, $params['contents']);
    fclose($fd);
    // Delete the file if it allready exists (this is needed on Win,
    // because it cannot overwrite files with rename()
    if (file_exists($params['filename'])) {
        @unlink($params['filename']);
    }
    @rename($_tmp_file, $params['filename']);
    @chmod($params['filename'], $smarty->_file_perms);
    return true;
}
开发者ID:Maharaja1,项目名称:thebest-social,代码行数:37,代码来源:core.write_file.php

示例13: downloadAction

 public function downloadAction()
 {
     $squadID = $this->params('id', 0);
     $squadRepo = $this->getEntityManager()->getRepository('Frontend\\Squads\\Entity\\Squad');
     /** @var Squad $squadEntity */
     $squadEntity = $squadRepo->findOneBy(array('user' => $this->identity(), 'id' => $squadID));
     if (!$squadEntity) {
         $this->flashMessenger()->addErrorMessage('Squad not found');
         return $this->redirect('frontend/user/squads');
     }
     $fileName = 'squad_file_pack_armasquads_' . $squadID;
     $zipTmpPath = tempnam(ini_get('upload_tmp_dir'), $fileName);
     $zip = new \ZipArchive();
     $zip->open($zipTmpPath, \ZipArchive::CHECKCONS);
     if (!$zip) {
         $this->flashMessenger()->addErrorMessage('Squad Package Download currently not possible');
         return $this->redirect('frontend/user/squads');
     }
     $zip->addFromString('squad.xml', file_get_contents('http://' . $_SERVER['SERVER_NAME'] . $this->url()->fromRoute('frontend/user/squads/xml', array('id' => $squadEntity->getPrivateID()))));
     if ($squadEntity->getSquadLogoPaa()) {
         $zip->addFile(ROOT_PATH . $squadEntity->getSquadLogoPaa(), basename($squadEntity->getSquadLogoPaa()));
     }
     $zip->addFromString('squad.dtd', file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/') . '/squad.dtd'));
     //$zip->addFromString('squad.xsl',file_get_contents(realpath(__DIR__ . '/../../../../view/squads/xml/').'/squad.xsl'));
     $zip->close();
     header('Content-Type: application/octet-stream');
     header("Content-Transfer-Encoding: Binary");
     header("Content-disposition: attachment; filename=\"" . basename($fileName) . ".zip\"");
     readfile($zipTmpPath);
     sleep(1);
     @unlink($zipTmpPath);
     die;
 }
开发者ID:PrimeAltis,项目名称:armasquads,代码行数:33,代码来源:SquadsController.php

示例14: process

 /**
  *
  * @param resource $pipe        	
  * @param string $job        	
  *
  * @throws PHPUnit_Framework_Exception
  *
  * @since Method available since Release 3.5.12
  */
 protected function process($pipe, $job)
 {
     if (!($this->tempFile = tempnam(sys_get_temp_dir(), 'PHPUnit')) || file_put_contents($this->tempFile, $job) === false) {
         throw new PHPUnit_Framework_Exception('Unable to write temporary file');
     }
     fwrite($pipe, '<?php require_once ' . var_export($this->tempFile, true) . '; ?>');
 }
开发者ID:sapwoo,项目名称:portfolio,代码行数:16,代码来源:Windows.php

示例15: prepWorkingDirectory

 /**
  * @beforeScenario
  */
 public function prepWorkingDirectory()
 {
     $this->workingDirectory = tempnam(sys_get_temp_dir(), 'phpspec-behat');
     $this->filesystem->remove($this->workingDirectory);
     $this->filesystem->mkdir($this->workingDirectory);
     chdir($this->workingDirectory);
 }
开发者ID:gajdaw,项目名称:stamp,代码行数:10,代码来源:FilesystemContext.php


注:本文中的tempnam函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。