本文整理汇总了PHP中Horde_Util::getTempFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Util::getTempFile方法的具体用法?PHP Horde_Util::getTempFile怎么用?PHP Horde_Util::getTempFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Util
的用法示例。
在下文中一共展示了Horde_Util::getTempFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: minify
/**
*/
public function minify()
{
if (!is_executable($this->_opts['java']) || !is_readable($this->_opts['closure'])) {
$this->_opts['logger']->log('The java path or Closure location can not be accessed.', Horde_Log::ERR);
return parent::minify();
}
$cmd = trim(escapeshellcmd($this->_opts['java']) . ' -jar ' . escapeshellarg($this->_opts['closure']));
if (isset($this->_opts['sourcemap']) && is_array($this->_data)) {
$this->_sourcemap = Horde_Util::getTempFile();
$cmd .= ' --create_source_map ' . escapeshellarg($this->_sourcemap) . ' --source_map_format=V3';
$suffix = "\n//# sourceMappingURL=" . $this->_opts['sourcemap'];
} else {
$suffix = '';
}
if (isset($this->_opts['cmdline'])) {
$cmd .= ' ' . trim($this->_opts['cmdline']);
}
if (is_array($this->_data)) {
$js = '';
foreach ($this->_data as $val) {
$cmd .= ' ' . $val;
}
} else {
$js = $this->_data;
}
$cmdline = new Horde_JavascriptMinify_Util_Cmdline();
return $cmdline->runCmd($js, $cmd, $this->_opts['logger']) . $suffix . $this->_sourceUrls();
}
示例2: minify
/**
*/
public function minify()
{
if (!is_executable($this->_opts['java']) || !is_readable($this->_opts['closure'])) {
$this->_opts['logger']->log('The java path or Closure location can not be accessed.', Horde_Log::ERR);
return parent::minify();
}
/* --warning_level QUIET - closure default is "DEFAULT" which will
* cause code with compiler warnings to output bad js (see Bug
* #13789) */
$cmd = trim(escapeshellcmd($this->_opts['java']) . ' -jar ' . escapeshellarg($this->_opts['closure']) . ' --warning_level QUIET');
if (isset($this->_opts['sourcemap']) && is_array($this->_data)) {
$this->_sourcemap = Horde_Util::getTempFile();
$cmd .= ' --create_source_map ' . escapeshellarg($this->_sourcemap) . ' --source_map_format=V3';
$suffix = "\n//# sourceMappingURL=" . $this->_opts['sourcemap'];
} else {
$suffix = '';
}
if (isset($this->_opts['cmdline'])) {
$cmd .= ' ' . trim($this->_opts['cmdline']);
}
if (is_array($this->_data)) {
$js = '';
foreach ($this->_data as $val) {
$cmd .= ' ' . $val;
}
} else {
$js = $this->_data;
}
$cmdline = new Horde_JavascriptMinify_Util_Cmdline();
return $cmdline->runCmd($js, $cmd, $this->_opts['logger']) . $suffix . $this->_sourceUrls();
}
示例3: getPDF
function getPDF()
{
$tmp_file = Horde_Util::getTempFile('fax', true, '/tmp');
$fp = fopen($tmp_file, 'wb');
fwrite($fp, $this->_data);
fclose($fp);
/* Convert the page from the postscript file to PDF. */
$command = sprintf('%s %s -', $this->_cmd['ps2pdf'], $tmp_file);
Horde::log('Executing command: ' . $command, 'DEBUG');
passthru($command);
}
示例4: testCacheAttachmentInFile
/**
* Test storing attachments.
*
* @return NULL
*/
public function testCacheAttachmentInFile()
{
$data = new Horde_Kolab_Storage_Data('contact');
$data->setFolder($this->folder);
$atc1 = Horde_Util::getTempFile();
$fh = fopen($atc1, 'w');
fwrite($fh, 'test');
fclose($fh);
$object = array('uid' => '1', 'full-name' => 'User Name', 'email' => 'user@example.org', 'inline-attachment' => array('test.txt'), '_attachments' => array('test.txt' => array('type' => 'text/plain', 'path' => $atc1, 'name' => 'test.txt')));
$result = $data->save($object);
$this->assertNoError($result);
$result = $data->getObject(1);
$this->assertNoError($result);
$this->assertTrue(isset($result['_attachments']['test.txt']));
// @todo: what introduces the \r?
$this->assertEquals("test\r", $data->getAttachment($result['_attachments']['test.txt']['key']));
}
示例5: validate
/**
* Validate the preconditions required for this release task.
*
* @param array $options Additional options.
*
* @return array An empty array if all preconditions are met and a list of
* error messages otherwise.
*/
public function validate($options)
{
$errors = array();
$testpkg = Horde_Util::getTempFile();
$archive = new Archive_Tar($testpkg, 'gz');
$archive->addString('a', 'a');
$archive->addString('b', 'b');
$results = exec('tar tzvf ' . $testpkg . ' 2>&1');
// MacOS tar doesn't error out, but only returns the first string (ending in 'a');
if (strpos($results, 'lone zero block') !== false || substr($results, -1, 1) == 'a') {
$errors[] = 'Broken Archive_Tar, upgrade first.';
}
$remote = new Horde_Pear_Remote();
try {
$exists = $remote->releaseExists($this->getComponent()->getName(), $this->getComponent()->getVersion());
if ($exists) {
$errors[] = sprintf('The remote server already has version "%s" for component "%s".', $this->getComponent()->getVersion(), $this->getComponent()->getName());
}
} catch (Horde_Http_Exception $e) {
$errors[] = 'Failed accessing the remote PEAR server.';
}
try {
Components_Helper_Version::validateReleaseStability($this->getComponent()->getVersion(), $this->getComponent()->getState('release'));
} catch (Components_Exception $e) {
$errors[] = $e->getMessage();
}
try {
Components_Helper_Version::validateApiStability($this->getComponent()->getVersion(), $this->getComponent()->getState('api'));
} catch (Components_Exception $e) {
$errors[] = $e->getMessage();
}
if (empty($options['releaseserver'])) {
$errors[] = 'The "releaseserver" option has no value. Where should the release be uploaded?';
}
if (empty($options['releasedir'])) {
$errors[] = 'The "releasedir" option has no value. Where is the remote pirum install located?';
}
return $errors;
}
示例6: minify
/**
*/
public function minify()
{
if (!is_readable($this->_opts['uglifyjs'])) {
$this->_opts['logger']->log('The UglifyJS binary cannot be accessed.', Horde_Log::ERR);
return parent::minify();
}
$cmd = escapeshellcmd($this->_opts['uglifyjs']);
if (isset($this->_opts['sourcemap']) && is_array($this->_data)) {
$this->_sourcemap = Horde_Util::getTempFile();
$cmd .= ' --source-map ' . escapeshellarg($this->_sourcemap) . ' --source-map-url ' . escapeshellarg($this->_opts['sourcemap']);
}
if (is_array($this->_data)) {
$js = '';
foreach ($this->_data as $val) {
$cmd .= ' ' . $val;
}
} else {
$js = $this->_data;
}
$cmdline = new Horde_JavascriptMinify_Util_Cmdline();
return $cmdline->runCmd($js, trim($cmd . ' ' . $this->_opts['cmdline']), $this->_opts['logger']) . $this->_sourceUrls();
}
示例7: process
/**
*/
public function process($css, $cacheid)
{
global $registry;
if (!empty($this->_params['filemtime'])) {
foreach ($css as &$val) {
$val['mtime'] = @filemtime($val['fs']);
}
}
$sig = hash(version_compare(PHP_VERSION, '5.4', '>=') ? 'fnv164' : 'sha1', json_encode($css) . $cacheid);
$filename = $sig . '.css';
$js_fs = $registry->get('staticfs', 'horde');
$path = $js_fs . '/' . $filename;
if (!file_exists($path)) {
$compress = new Horde_Themes_Css_Compress();
$temp = Horde_Util::getTempFile('staticcss', true, $js_fs);
if (!file_put_contents($temp, $compress->compress($css), LOCK_EX) || !chmod($temp, 0777 & ~umask()) || !rename($temp, $path)) {
Horde::log('Could not write cached CSS file to disk.', 'EMERG');
return array();
}
}
return array(Horde::url($registry->get('staticuri', 'horde') . '/' . $filename, true, array('append_session' => -1)));
}
示例8: _handleFileUpload
/**
* Checks for a file uploaded via the pluploader. If one is found, handle
* it, send the server json response and exit.
*/
protected function _handleFileUpload()
{
if ($filename = Horde_Util::getFormData('name')) {
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
$type = $_SERVER["HTTP_CONTENT_TYPE"];
} elseif (isset($_SERVER["CONTENT_TYPE"])) {
$type = $_SERVER["CONTENT_TYPE"];
}
if (empty($type) || $type == 'application/octet-stream') {
$temp = Horde_Util::getTempFile('', true);
$out = fopen($temp, 'w+');
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen("php://input", "rb");
if ($in) {
stream_copy_to_stream($in, $out);
rewind($out);
fclose($in);
} else {
fclose($out);
header('Content-Type: application/json');
echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open input stream." } }';
exit;
}
} else {
header('Content-Type: application/json');
echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open output stream." } }';
exit;
}
// // Don't know type. Try to deduce it.
if (!($type = Horde_Mime_Magic::analyzeFile($temp, isset($GLOBALS['conf']['mime']['magic_db']) ? $GLOBALS['conf']['mime']['magic_db'] : null))) {
$type = Horde_Mime_Magic::filenameToMime($filename);
}
} elseif (strpos($type, "multipart") !== false) {
// Handle mulitpart uploads
$temp = Horde_Util::getTempFile('', true);
$out = fopen($temp, 'w+');
if ($out) {
$in = fopen($_FILES['file']['tmp_name'], 'rb');
if ($in) {
stream_copy_to_stream($in, $out);
rewind($out);
fclose($in);
} else {
fclose($out);
header('Content-Type: application/json');
echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open input stream." } }';
exit;
}
} else {
header('Content-Type: application/json');
echo '{ "status" : "500", "file": "' . $temp . '", error" : { "message": "Failed to open output stream." } }';
exit;
}
}
// Figure out what to do with the file
if (in_array($type, array('x-extension/zip', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip')) || Horde_Mime_Magic::filenameToMime($temp) == 'application/zip') {
// ZIP file
try {
$image_ids = $this->_handleZip($temp);
} catch (Ansel_Exception $e) {
$notification->push(sprintf(_("There was an error processing the uploaded archive: %s"), $e->getMessage()), 'horde.error');
}
} else {
// Try and make sure the image is in a recognizeable format.
if (getimagesize($temp) === false) {
header('Content-Type: application/json');
echo '{ "status" : "400", "error" : { "message": "Not a valid, supported image file." }, "id" : "id" }';
exit;
}
// Add the image to the gallery
$image_data = array('image_filename' => $filename, 'image_type' => $type, 'data' => stream_get_contents($out));
fclose($out);
try {
$image_ids = array($this->_gallery->addImage($image_data));
} catch (Ansel_Exception $e) {
header('Content-Type: application/json');
echo '{ "status" : "400", "error" : { "message": "Not a valid, supported image file." }, "id" : "id" }';
exit;
}
unset($data);
}
// Try to auto generate some thumbnails.
$qtask = new Ansel_Queue_ProcessThumbs($image_ids);
$queue = $GLOBALS['injector']->getInstance('Horde_Queue_Storage');
$queue->add($qtask);
header('Content-Type: application/json');
echo '{ "status" : "200", "error" : {} }';
exit;
}
}
示例9: annotate
/**
* TODO
*
* @throws Horde_Vcs_Exception
*/
public function annotate($fileob, $rev)
{
$this->assertValidRevision($rev);
$tmpfile = Horde_Util::getTempFile('vc', true, $this->_paths['temp']);
$where = $fileob->getSourcerootPath();
$pipe = popen(escapeshellcmd($this->getPath('cvs')) . ' -n server > ' . escapeshellarg($tmpfile), VC_WINDOWS ? 'wb' : 'w');
$out = array('Root ' . $this->sourceroot, 'Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E', 'UseUnchanged', 'Argument -r', 'Argument ' . $rev, 'Argument ' . $where);
$dirs = explode('/', dirname($where));
while (count($dirs)) {
$out[] = 'Directory ' . implode('/', $dirs);
$out[] = $this->sourceroot . '/' . implode('/', $dirs);
array_pop($dirs);
}
$out[] = 'Directory .';
$out[] = $this->sourceroot;
$out[] = 'annotate';
foreach ($out as $line) {
fwrite($pipe, "{$line}\n");
}
pclose($pipe);
if (!($fl = fopen($tmpfile, VC_WINDOWS ? 'rb' : 'r'))) {
return false;
}
$lines = array();
$line = fgets($fl, 4096);
// Windows versions of cvs always return $where with forwards slashes.
if (VC_WINDOWS) {
$where = str_replace(DIRECTORY_SEPARATOR, '/', $where);
}
while ($line && !preg_match("|^E\\s+Annotations for {$where}|", $line)) {
$line = fgets($fl, 4096);
}
if (!$line) {
throw new Horde_Vcs_Exception('Unable to annotate; server said: ' . $line);
}
$lineno = 1;
while ($line = fgets($fl, 4096)) {
if (preg_match('/^M\\s+([\\d\\.]+)\\s+\\((.+)\\s+(\\d+-\\w+-\\d+)\\):.(.*)$/', $line, $regs)) {
$lines[] = array('rev' => $regs[1], 'author' => trim($regs[2]), 'date' => $regs[3], 'line' => $regs[4], 'lineno' => $lineno++);
}
}
fclose($fl);
return $lines;
}
示例10: _process
/**
*/
protected function _process($scripts)
{
global $registry;
if (empty($scripts)) {
return array();
}
$tmp = array();
foreach ($scripts as $val) {
$tmp[] = $val->modified;
}
$mtime = max($tmp);
$hashes = array_keys($scripts);
sort($hashes);
/* Use 64-bit FNV algo (instead of 32-bit) since this is a
* publicly accessible key and we want to guarantee filename
* is unique. */
$sig = hash(version_compare(PHP_VERSION, '5.4', '>=') ? 'fnv164' : 'sha1', json_encode($hashes) . $mtime);
$js_filename = $sig . '.js';
$js_fs = $registry->get('staticfs', 'horde');
$js_path = $js_fs . '/' . $js_filename;
$js_url = $registry->get('staticuri', 'horde') . '/' . $js_filename;
$out = array($js_url);
if (file_exists($js_path)) {
return $out;
}
/* Check for existing process creating compressed file. Maximum 15
* seconds wait time. */
for ($i = 0; $i < 15; ++$i) {
if (file_exists($js_path . '.lock')) {
sleep(1);
} elseif ($i) {
return $out;
} else {
touch($js_path . '.lock');
break;
}
}
if (!isset($this->_compress)) {
$this->_compress = new Horde_Script_Compress($this->_params['compress'], $this->_params);
}
$sourcemap_url = $js_url . '.map';
$jsmin = $this->_compress->getMinifier($scripts, $sourcemap_url);
$temp = Horde_Util::getTempFile('staticjs', true, $js_fs);
if (!file_put_contents($temp, $jsmin->minify(), LOCK_EX) || !chmod($temp, 0777 & ~umask()) || !rename($temp, $js_path)) {
Horde::log('Could not write cached JS file to disk.', Horde_Log::EMERG);
} elseif ($this->_compress->sourcemap_support) {
file_put_contents($js_path . '.map', $jsmin->sourcemap(), LOCK_EX);
}
unlink($js_path . '.lock');
return $out;
}
示例11: set
/**
*/
public function set($key, $data, $lifetime = 0)
{
$filename = $this->_keyToFile($key, true);
$tmp_file = Horde_Util::getTempFile('HordeCache', true, $this->_params['dir']);
if (isset($this->_params['umask'])) {
chmod($tmp_file, 0666 & ~$this->_params['umask']);
}
if (file_put_contents($tmp_file, $data) === false) {
throw new Horde_Cache_Exception('Cannot write to cache directory ' . $this->_params['dir']);
}
@rename($tmp_file, $filename);
if ($lifetime && ($fp = @fopen(dirname($filename) . '/' . self::GC_FILE, 'a'))) {
// This may result in duplicate entries in GC_FILE, but we
// will take care of these whenever we do GC and this is quicker
// than having to check every time we access the file.
fwrite($fp, $filename . "\t" . (time() + $lifetime) . "\n");
fclose($fp);
}
}
示例12: store
/**
* Stores changed preferences in the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @throws Horde_Prefs_Exception
*/
public function store($scope_ob)
{
$this->_loadFileCache();
/* Driver has no support for storing locked status. */
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
unset($this->_fileCache[$scope_ob->scope][$name]);
} else {
$this->_fileCache[$scope_ob->scope][$name] = $value;
}
}
$tmp_file = Horde_Util::getTempFile('PrefsFile', true, $this->_params['directory']);
if (file_put_contents($tmp_file, serialize($this->_fileCache)) === false || @rename($tmp_file, $this->_fullpath) === false) {
throw new Horde_Prefs_Exception(sprintf('Write of preferences to %s failed', $this->_fullpath));
}
}
示例13: toFile
/**
* Saves image data to file.
*
* If $data is false, saves current image data after performing any pending
* operations on the data. If $data contains raw image data, saves that
* data to file without regard for the current image data.
*
* @param string String of binary image data.
*
* @return string Path to temporary file.
*/
public function toFile($data = null)
{
$tmp = Horde_Util::getTempFile('img', false, $this->_tmpdir);
$fp = fopen($tmp, 'wb');
fwrite($fp, $data ?: $this->raw());
fclose($fp);
return $tmp;
}
示例14: executeConvertCmd
/**
* Method to execute a raw command directly in convert.
*
* Useful for executing more involved operations that may require multiple
* convert commands piped into each other for example. Really designed for
* use by Im based Horde_Image_Effect objects.
*
* The input and output files are quoted and substituted for __FILEIN__ and
* __FILEOUT__ respectfully. In order to support piped convert commands,
* the path to the convert command is substitued for __CONVERT__ (but the
* initial convert command is added automatically).
*
* @param string $cmd The command string, with substitutable tokens
* @param array $values Any values that should be substituted for tokens.
*/
public function executeConvertCmd($cmd, $values = array())
{
// First, get a temporary file for the input
if (strpos($cmd, '__FILEIN__') !== false) {
$tmpin = $this->toFile($this->_data);
} else {
$tmpin = '';
}
// Now an output file
$tmpout = Horde_Util::getTempFile('img', false, $this->_tmpdir);
// Substitue them in the cmd string
$cmd = str_replace(array('__FILEIN__', '__FILEOUT__', '__CONVERT__'), array('"' . $tmpin . '"', '"' . $tmpout . '"', $this->_convert), $cmd);
//TODO: See what else needs to be replaced.
$cmd = $this->_convert . ' ' . $cmd . ' 2>&1';
// Log it
$this->_logDebug(sprintf("convert command executed by Horde_Image_im::executeConvertCmd(): %s", $cmd));
exec($cmd, $output, $retval);
if ($retval) {
$this->_logErr(sprintf("Error running command: %s", $cmd . "\n" . implode("\n", $output)));
}
$this->_data = file_get_contents($tmpout);
@unlink($tmpin);
@unlink($tmpout);
}
示例15: _download
/**
* Downloads a timezone database.
*
* @throws Horde_Timezone_Exception if downloading fails.
*/
protected function _download()
{
$url = @parse_url($this->_params['location']);
if (!isset($url['scheme'])) {
throw new Horde_Timezone_Exception('"location" parameter is missing an URL scheme.');
}
if (!in_array($url['scheme'], array('http', 'ftp', 'file'))) {
throw new Horde_Timezone_Exception(sprintf('Unsupported URL scheme "%s"', $url['scheme']));
}
if ($url['scheme'] == 'http') {
if (isset($this->_params['client'])) {
$client = $this->_params['client'];
} else {
$client = new Horde_Http_Client();
}
$response = $client->get($this->_params['location']);
$this->_tmpfile = Horde_Util::getTempFile('', true, isset($this->_params['temp']) ? $this->_params['temp'] : '');
stream_copy_to_stream($response->getStream(), fopen($this->_tmpfile, 'w'));
return;
}
if ($url['scheme'] == 'ftp') {
try {
$vfs = new Horde_Vfs_Ftp(array('hostspec' => $url['host'], 'username' => 'anonymous', 'password' => 'anonymous', 'pasv' => true));
$this->_tmpfile = $vfs->readFile(dirname($url['path']), basename($url['path']));
} catch (Horde_Vfs_Exception $e) {
throw new Horde_Timezone_Exception($e);
}
} else {
$this->_tmpfile = $this->_params['location'];
if (!is_readable($this->_tmpfile)) {
$e = new Horde_Timezone_Exception(sprintf('Unable to open file %s.', $this->_params['location']));
if (isset($php_errormsg)) {
$e->details = $php_errormsg;
}
throw $e;
}
}
}