コード例 #1
1
ファイル: FdfFile.php プロジェクト: aviddv1/php-pdftk
 /**
  * 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);
 }
コード例 #2
0
ファイル: hunteron.php プロジェクト: RenzcPHP/spider
 function __construct($loginname, $membername, $password)
 {
     $this->cookie_file = tempnam('./tmp', 'HUNTERON');
     $this->loginname = $loginname;
     $this->membername = $membername;
     $this->password = $password;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
ファイル: PdfPublisher.php プロジェクト: raulfraile/easybook
 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";
         }
     }
 }
コード例 #5
0
ファイル: XLSReporte.php プロジェクト: codethics/proteoerp
 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));
 }
コード例 #6
0
 /**
  * {@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);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
ファイル: util.php プロジェクト: alopix/aoxPages
 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;
 }
コード例 #9
0
ファイル: LoaderTest.php プロジェクト: pear/xml_xrd
 /**
  * @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);
 }
コード例 #10
0
 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;
 }
コード例 #11
0
ファイル: CrossCheckTest.php プロジェクト: khalid05/symfony
 /**
  * @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');
 }
コード例 #12
0
/**
 * 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;
}
コード例 #13
0
 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;
 }
コード例 #14
0
ファイル: Windows.php プロジェクト: sapwoo/portfolio
 /**
  *
  * @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) . '; ?>');
 }
コード例 #15
0
ファイル: FilesystemContext.php プロジェクト: gajdaw/stamp
 /**
  * @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);
 }
コード例 #16
0
ファイル: TemplateProcessor.php プロジェクト: cakpep/spk-tht
 /**
  * @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception.
  *
  * @param string $documentTemplate The fully qualified template filename.
  * @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
  * @throws \PhpOffice\PhpWord\Exception\CopyFileException
  */
 public function __construct($documentTemplate)
 {
     // Temporary document filename initialization
     $this->temporaryDocumentFilename = tempnam(Settings::getTempDir(), 'PhpWord');
     if (false === $this->temporaryDocumentFilename) {
         throw new CreateTemporaryFileException();
     }
     // Template file cloning
     if (false === copy($documentTemplate, $this->temporaryDocumentFilename)) {
         throw new CopyFileException($documentTemplate, $this->temporaryDocumentFilename);
     }
     // Temporary document content extraction
     $this->zipClass = new ZipArchive();
     $this->zipClass->open($this->temporaryDocumentFilename);
     $index = 1;
     while ($this->zipClass->locateName($this->getHeaderName($index)) !== false) {
         $this->temporaryDocumentHeaders[$index] = $this->zipClass->getFromName($this->getHeaderName($index));
         $index++;
     }
     $index = 1;
     while ($this->zipClass->locateName($this->getFooterName($index)) !== false) {
         $this->temporaryDocumentFooters[$index] = $this->zipClass->getFromName($this->getFooterName($index));
         $index++;
     }
     $this->temporaryDocumentMainPart = $this->zipClass->getFromName('word/document.xml');
 }
コード例 #17
0
 public static function setUpBeforeClass()
 {
     $reflect = new \ReflectionClass(__CLASS__);
     self::$directory = @tempnam(sys_get_temp_dir(), $reflect->getShortName() . '-');
     @unlink(self::$directory);
     @mkdir(self::$directory);
 }
コード例 #18
0
 public function createUploadFile()
 {
     $filename = tempnam($this->uploadDir, 'zfc');
     file_put_contents($filename, sprintf('File created by %s', __CLASS__));
     $file = ['name' => 'test.txt', 'type' => 'text/plain', 'tmp_name' => $filename, 'size' => filesize($filename), 'error' => UPLOAD_ERR_OK];
     return $file;
 }
コード例 #19
0
/**
 * 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);
    if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
        // On platforms and filesystems that cannot overwrite with rename()
        // delete the file before renaming it -- because windows always suffers
        // this, it is short-circuited to avoid the initial rename() attempt
        @unlink($params['filename']);
        @rename($_tmp_file, $params['filename']);
    }
    @chmod($params['filename'], $smarty->_file_perms);
    return true;
}
コード例 #20
0
 public function filterLoad(AssetInterface $asset)
 {
     $sassProcessArgs = array();
     if (null !== $this->nodePath) {
         $sassProcessArgs[] = $this->nodePath;
     }
     $sassProcessArgs[] = $this->sassPath;
     $pb = $this->createProcessBuilder($sassProcessArgs);
     if ($dir = $asset->getSourceDirectory()) {
         $pb->add('--include-path')->add($dir);
     }
     if ($this->style) {
         $pb->add('--output-style')->add($this->style);
     }
     if ($this->sourceMap) {
         $pb->add('--source-map');
     }
     if ($this->debugInfo) {
         $pb->add('--source-comments');
     }
     foreach ($this->loadPaths as $loadPath) {
         $pb->add('--include-path')->add($loadPath);
     }
     // input
     $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_sass'));
     file_put_contents($input, $asset->getContent());
     $pb->add('--stdout');
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 !== $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #21
0
 public function display($cachable = false, $urlparams = false)
 {
     JRequest::setVar('view', JRequest::getCmd('view', 'Orphans'));
     if (isset($_POST['_orphanaction']) && $_POST['_orphanaction'] == "zipIt") {
         $file = tempnam("tmp", "zip");
         $zip = new ZipArchive();
         $zip->open($file, ZipArchive::OVERWRITE);
         foreach ($_POST['tozip'] as $_file) {
             $zip->addFile(JPATH_ROOT . "/" . $_file, $_file);
         }
         $zip->close();
         header('Content-Type: application/zip');
         header('Content-Length: ' . filesize($file));
         header('Content-Disposition: attachment; filename="orphans.zip"');
         readfile($file);
         unlink($file);
         die;
     } else {
         if (isset($_POST['_orphanaction']) && $_POST['_orphanaction'] == "delete" && isset($_POST['_confirmAction'])) {
             foreach ($_POST['tozip'] as $_file) {
                 unlink(JPATH_ROOT . "/" . $_file);
             }
         }
     }
     // call parent behavior
     parent::display($cachable);
 }
コード例 #22
0
ファイル: SelfupdateCommand.php プロジェクト: pagekit/pagekit
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         if (!$this->option('url')) {
             $output->write('Requesting Version...');
             $versions = $this->getVersions();
             $output->writeln('<info>done.</info>');
             $output->writeln('');
             $output->writeln('<comment>Latest Version: ' . $versions['latest']['version'] . '</comment> ');
             $output->writeln('');
             if (!$this->confirm('Update to Version ' . $versions['latest']['version'] . '? [y/n]')) {
                 return;
             }
             $output->writeln('');
             $url = $versions['latest']['url'];
         } else {
             $url = $this->option('url');
         }
         $tmpFile = tempnam($this->container['path.temp'], 'update_');
         $output->write('Downloading...');
         $this->download($url, $tmpFile);
         $output->writeln('<info>done.</info>');
         $updater = new SelfUpdater($output);
         $updater->update($tmpFile);
         $output->write('Migrating...');
         system(sprintf('php %s migrate', $_SERVER['PHP_SELF']));
     } catch (\Exception $e) {
         if (isset($tmpFile) && file_exists($tmpFile)) {
             unlink($tmpFile);
         }
         throw $e;
     }
 }
コード例 #23
0
 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');
 }
コード例 #24
0
ファイル: simuledit.php プロジェクト: BogusCurry/pmwiki
function Merge($newtext,$oldtext,$pagetext) {
  global $WorkDir,$SysMergeCmd, $SysMergePassthru;
  SDV($SysMergeCmd,"/usr/bin/diff3 -L '' -L '' -L '' -m -E");
  if (substr($newtext,-1,1)!="\n") $newtext.="\n";
  if (substr($oldtext,-1,1)!="\n") $oldtext.="\n";
  if (substr($pagetext,-1,1)!="\n") $pagetext.="\n";
  $tempnew = tempnam($WorkDir,"new");
  $tempold = tempnam($WorkDir,"old");
  $temppag = tempnam($WorkDir,"page");
  if ($newfp=fopen($tempnew,'w')) { fputs($newfp,$newtext); fclose($newfp); }
  if ($oldfp=fopen($tempold,'w')) { fputs($oldfp,$oldtext); fclose($oldfp); }
  if ($pagfp=fopen($temppag,'w')) { fputs($pagfp,$pagetext); fclose($pagfp); }
  $mergetext = '';
  if (IsEnabled($SysMergePassthru, 0)) {
    ob_start();
    passthru("$SysMergeCmd $tempnew $tempold $temppag");
    $mergetext = ob_get_clean();
  }
  else {
    $merge_handle = popen("$SysMergeCmd $tempnew $tempold $temppag",'r');
    if ($merge_handle) {
      while (!feof($merge_handle)) $mergetext .= fread($merge_handle,4096);
      pclose($merge_handle);
    }
  }
  @unlink($tempnew); @unlink($tempold); @unlink($temppag);
  return $mergetext;
}
コード例 #25
0
 public function filterDump(AssetInterface $asset)
 {
     $pb = $this->createProcessBuilder(array($this->jpegtranBin));
     if ($this->optimize) {
         $pb->add('-optimize');
     }
     if ($this->copy) {
         $pb->add('-copy')->add($this->copy);
     }
     if ($this->progressive) {
         $pb->add('-progressive');
     }
     if (null !== $this->restart) {
         $pb->add('-restart')->add($this->restart);
     }
     $pb->add($input = tempnam(sys_get_temp_dir(), 'assetic_jpegtran'));
     file_put_contents($input, $asset->getContent());
     $proc = $pb->getProcess();
     $code = $proc->run();
     unlink($input);
     if (0 < $code) {
         throw FilterException::fromProcess($proc)->setInput($asset->getContent());
     }
     $asset->setContent($proc->getOutput());
 }
コード例 #26
0
ファイル: General.php プロジェクト: sidouglas/aussieBumEDM
 function __construct()
 {
     $this->auth = null;
     $this->container = null;
     $this->temp_name = tempnam(get_tmpdir(), "php-cloudfiles");
     $this->object_data = "Some Random text for object data";
 }
コード例 #27
0
 /**
  * @covers Alchemy\Phrasea\SearchEngine\SphinxSearch\SphinxSearchEngine
  */
 public function bootTestCase()
 {
     $binaryFinder = new ExecutableFinder();
     $indexer = $binaryFinder->find('indexer');
     $searchd = $binaryFinder->find('searchd');
     if (!$indexer || !$searchd) {
         self::$skipped = true;
         return;
     }
     $app = self::$DI['app'];
     $appbox = $app['phraseanet.appbox'];
     $app['conf']->set(['main', 'search-engine', 'options'], ['host' => '127.0.0.1', 'port' => 9312, 'rt_host' => '127.0.0.1', 'rt_port' => 9306]);
     self::$searchEngine = SphinxSearchEngine::create($app, $app['conf']->get(['main', 'search-engine', 'options']));
     self::$config = tempnam(sys_get_temp_dir(), 'tmp_sphinx.conf');
     $configuration = self::$searchEngine->getConfigurationPanel()->getConfiguration();
     $configuration['date_fields'] = [];
     foreach ($appbox->get_databoxes() as $databox) {
         foreach ($databox->get_meta_structure() as $databox_field) {
             if ($databox_field->get_type() != \databox_field::TYPE_DATE) {
                 continue;
             }
             $configuration['date_fields'][] = $databox_field->get_name();
         }
     }
     $configuration['date_fields'] = array_unique($configuration['date_fields']);
     self::$searchEngine->getConfigurationPanel()->saveConfiguration($configuration);
     $configFile = self::$searchEngine->getConfigurationPanel()->generateSphinxConf($appbox->get_databoxes(), $configuration);
     file_put_contents(self::$config, $configFile);
     $process = new Process($indexer . ' --all -c ' . self::$config);
     $process->run();
     self::$searchd = new Process($searchd . ' -c ' . self::$config);
     self::$searchd->run();
     self::$searchEngine = SphinxSearchEngine::create($app, $app['conf']->get(['main', 'search-engine', 'options']));
     self::$searchEngineClass = 'Alchemy\\Phrasea\\SearchEngine\\SphinxSearch\\SphinxSearchEngine';
 }
コード例 #28
0
ファイル: Filesystem.php プロジェクト: kayneth/site_enchere
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $dir = dirname($key);
     if (!is_dir($dir)) {
         if (false === @mkdir($dir, 0777, true)) {
             clearstatcache(false, $dir);
             if (!is_dir($dir)) {
                 throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
             }
         }
     } elseif (!is_writable($dir)) {
         throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
     }
     $tmpFile = tempnam($dir, basename($key));
     if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
         @chmod($key, 0666 & ~umask());
         if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
             // Compile cached file into bytecode cache
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($key, true);
             } elseif (function_exists('apc_compile_file')) {
                 apc_compile_file($key);
             }
         }
         return;
     }
     throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
 }
コード例 #29
0
ファイル: StreamTest.php プロジェクト: Golpha/Http
 public function testIsWritableAndReadable()
 {
     $fileName = tempnam(__DIR__, '_none_');
     $stream = new Stream($fileName, "r");
     $this->assertFalse($stream->isWritable());
     $this->assertTrue($stream->isReadable());
     try {
         $stream->write('...');
         $this->fail();
     } catch (RuntimeException $e) {
         $this->assertEquals('Stream is not writable.', $e->getMessage());
     }
     $stream = new Stream($fileName, "w");
     $this->assertTrue($stream->isWritable());
     $this->assertFalse($stream->isReadable());
     try {
         $stream->read(1);
         $this->fail();
     } catch (RuntimeException $e) {
         $this->assertEquals('Stream is not readable.', $e->getMessage());
     }
     $stream = new Stream($fileName, "r+");
     $this->assertTrue($stream->isWritable());
     $this->assertTrue($stream->isReadable());
     $stream = new Stream($fileName, "w+");
     $this->assertTrue($stream->isWritable());
     $this->assertTrue($stream->isReadable());
     @unlink($fileName);
 }
コード例 #30
-2
ファイル: Uploader.php プロジェクト: uiDeveloper116/webstore
 public static function upload_large($file, $options = array())
 {
     $src = fopen($file, 'r');
     $temp_file_name = tempnam(sys_get_temp_dir(), 'cldupload.' + pathinfo($file, PATHINFO_EXTENSION));
     $upload = $upload_id = NULL;
     $public_id = \Cloudinary::option_get($upload, "public_id");
     $index = 1;
     while (!feof($src)) {
         $dest = fopen($temp_file_name, 'w');
         stream_copy_to_stream($src, $dest, 20000000);
         fclose($dest);
         try {
             $upload = Uploader::upload_large_part($temp_file_name, array_merge($options, array("public_id" => $public_id, "upload_id" => $upload_id, "part_number" => $index, "final" => feof($src))));
         } catch (\Exception $e) {
             unlink($temp_file_name);
             fclose($src);
             throw $e;
         }
         $upload_id = \Cloudinary::option_get($upload, "upload_id");
         $public_id = \Cloudinary::option_get($upload, "public_id");
         $index += 1;
     }
     unlink($temp_file_name);
     fclose($src);
     return $upload;
 }