本文整理汇总了PHP中tmpfile函数的典型用法代码示例。如果您正苦于以下问题:PHP tmpfile函数的具体用法?PHP tmpfile怎么用?PHP tmpfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tmpfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
function show()
{
$folder = 'tmp/';
if (isset($_REQUEST['qqfile'])) {
$file = $_REQUEST['qqfile'];
$path = $folder . $file;
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $_SERVER["CONTENT_LENGTH"]) {
die("{'error':'size error'}");
}
if (is_writable($folder)) {
$target = fopen($path, 'w');
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
echo "{success:true, target:'{$file}'}";
} else {
die("{'error':'not writable: {$path}'}");
}
} else {
$file = $_FILES['qqfile']['name'];
$path = $folder . $file;
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
die("{'error':'permission denied'}");
}
echo "{success:true, target:'{$file}'}";
}
}
示例2: callWebService
function callWebService($url, $method, $data = "")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch,CURLOPT_HEADER, 0);
$fp = null;
if ($method == "PUT") {
curl_setopt($ch, CURLOPT_PUT, 1);
$fp = tmpfile();
fwrite($fp, $data);
fseek($fp, 0);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
} elseif ($method == "POST") {
$post = array("data" => $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
} elseif ($method == "DELETE") {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($fp) {
fclose($fp);
}
curl_close($ch);
return array("code" => $httpCode, "content" => $response);
}
示例3: create_tmp_file
function create_tmp_file($data)
{
$tmp_file = tmpfile();
fwrite($tmp_file, $data);
rewind($tmp_file);
return $tmp_file;
}
示例4: createTmpFile
public static function createTmpFile($data)
{
$tmp_file = tmpfile();
fwrite($tmp_file, $data);
rewind($tmp_file);
return $tmp_file;
}
示例5: createTables
private function createTables()
{
/* @var $entityManager \Doctrine\ORM\EntityManager */
$entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_zfcDatagrid');
/* @var $cli \Symfony\Component\Console\Application */
$cli = $this->getServiceLocator()->get('doctrine.cli');
$helperSet = $cli->getHelperSet();
$helperSet->set(new EntityManagerHelper($entityManager), 'em');
$fp = tmpfile();
// $input = new StringInput('orm:schema-tool:create --dump-sql');
$input = new StringInput('orm:schema-tool:create');
/* @var $command \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand */
$command = $cli->get('orm:schema-tool:create');
$returnCode = $command->run($input, new StreamOutput($fp));
$phpArray = $this->getServiceLocator()->get('Zf2datatable.examples.data.phpArray');
$persons = $phpArray->getPersons();
$this->createData(new Person(), $persons);
// $entityManager->f
// fseek($fp, 0);
// $output = '';
// while (! feof($fp)) {
// $output = fread($fp, 4096);
// }
// fclose($fp);
// echo '<pre>';
// print_r($output);
// print_r($returnCode);
// echo 'DONE!';
// exit();
}
示例6: testSettingServices
public function testSettingServices()
{
$logger = new Mustache_Logger_StreamLogger(tmpfile());
$loader = new Mustache_Loader_StringLoader();
$tokenizer = new Mustache_Tokenizer();
$parser = new Mustache_Parser();
$compiler = new Mustache_Compiler();
$mustache = new Mustache_Engine();
$cache = new Mustache_Cache_FilesystemCache(self::$tempDir);
$this->assertNotSame($logger, $mustache->getLogger());
$mustache->setLogger($logger);
$this->assertSame($logger, $mustache->getLogger());
$this->assertNotSame($loader, $mustache->getLoader());
$mustache->setLoader($loader);
$this->assertSame($loader, $mustache->getLoader());
$this->assertNotSame($loader, $mustache->getPartialsLoader());
$mustache->setPartialsLoader($loader);
$this->assertSame($loader, $mustache->getPartialsLoader());
$this->assertNotSame($tokenizer, $mustache->getTokenizer());
$mustache->setTokenizer($tokenizer);
$this->assertSame($tokenizer, $mustache->getTokenizer());
$this->assertNotSame($parser, $mustache->getParser());
$mustache->setParser($parser);
$this->assertSame($parser, $mustache->getParser());
$this->assertNotSame($compiler, $mustache->getCompiler());
$mustache->setCompiler($compiler);
$this->assertSame($compiler, $mustache->getCompiler());
$this->assertNotSame($cache, $mustache->getCache());
$mustache->setCache($cache);
$this->assertSame($cache, $mustache->getCache());
}
示例7: fromFile_exceed_buffer
/**
* @test
*/
public function fromFile_exceed_buffer()
{
//Create a 10k temp file
$temp = tmpfile();
fwrite($temp, str_repeat("1", 10000));
$meta_data = stream_get_meta_data($temp);
$filename = $meta_data["uri"];
/** @var LoopInterface $loop */
$loop = \EventLoop\getLoop();
$source = new FromFileObservable($filename);
$result = false;
$complete = false;
$error = false;
$source->subscribe(new CallbackObserver(function ($value) use(&$result) {
$result = $value;
}, function ($e) use(&$error) {
$error = true;
}, function () use(&$complete) {
$complete = true;
}));
$loop->tick();
$this->assertEquals("4096", strlen($result));
$this->assertFalse($complete);
$this->assertFalse($error);
$loop->tick();
$this->assertEquals("4096", strlen($result));
$this->assertFalse($complete);
$this->assertFalse($error);
$loop->tick();
$this->assertEquals("1808", strlen($result));
$this->assertTrue($complete);
$this->assertFalse($error);
}
示例8: connect
function connect($filename, $encode = "EUC-JP")
{
$allData = array();
//一時ファイルを使い、一気に文字コード変換
if (!file_exists($filename)) {
return false;
}
if (!($fileData = file_get_contents($filename))) {
return false;
}
$fileData = mb_convert_encoding($fileData, "UTF-8", $encode);
// 一時ファイルに書き込み
$handle = tmpfile();
$size = fwrite($handle, $fileData);
fseek($handle, 0);
while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
$line = array();
foreach ($data as $val) {
echo $val;
$line[] = trim($val);
}
$allData[] = $line;
}
fclose($handle);
if ($this->allData = $allData) {
return true;
} else {
return false;
}
}
示例9: executeOnNodeDriver
/**
* Sends a command with arguments to NodeJS process
* which executes and when done returns the response
* to this driver if no errors occur a Array returns
*
* @param string $action Command in NodeJS process
* @return Array|Boolean|String
* @throws NodeDriverException
*/
private function executeOnNodeDriver($action)
{
$args = func_get_args();
array_shift($args);
$jsonString = json_encode(["command" => $action, "params" => $args]);
$tmpHandle = tmpfile();
fwrite($tmpHandle, $jsonString);
$metaDatas = stream_get_meta_data($tmpHandle);
$tmpFilename = $metaDatas['uri'];
$execString = "node " . realpath(dirname(__FILE__) . '/../../../vendor/node/index.js') . ' ' . $tmpFilename;
//debug($execString);
try {
$response = exec($execString, $output, $return_var);
} catch (Exception $e) {
//debug($e);
}
//debug($response);
fclose($tmpHandle);
if ($return_var != 0) {
throw new NodeDriverException([$action, print_r($args, true), $response]);
}
try {
$response = json_decode($response, true);
} catch (Exception $ex) {
}
return $response;
}
示例10:
/**
* Open the stream and return the associated resource.
*
* @param string $streamName Stream name (here, it is
* null).
* @param \Hoa\Stream\Context $context Context.
* @return resource
* @throws \Hoa\File\Exception
*/
protected function &_open($streamName, \Hoa\Stream\Context $context = null)
{
if (false === ($out = @tmpfile())) {
throw new File\Exception('Failed to open a temporary stream.', 0);
}
return $out;
}
示例11: save
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path, $filename)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
if ($realSize != $this->getSize()) {
return false;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
//insert data into attachment table
if (!class_exists('VmConfig')) {
require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php';
}
$thumb_width = VmConfig::loadConfig()->get('img_width');
$user_s =& JFactory::getUser();
$user_id = $user_s->id;
$product_vm_id = JRequest::getInt('virtuemart_product_id');
$database =& JFactory::getDBO();
$gallery = new stdClass();
$gallery->id = 0;
$gallery->virtuemart_user_id = $user_id;
$gallery->virtuemart_product_id = $product_vm_id;
$gallery->file_name = $filename;
$gallery->created_on = date('Y-m-d,H:m:s');
if (!$database->insertObject('#__virtuemart_product_attachments', $gallery, 'id')) {
echo $database->stderr();
return false;
}
// end of insert data
return true;
}
示例12: executeHttpPost
public function executeHttpPost($url, $postData)
{
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_ENCODING, "gzip");
curl_setopt($curlHandler, CURLOPT_URL, $url);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandler, CURLOPT_CAINFO, realpath(dirname(__FILE__)) . "/startssl.pem");
// THE CRAPIEST THING I'VE EVER SEEN :
$putData = tmpfile();
fwrite($putData, $putString);
fseek($putData, 0);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $postData);
try {
$body = curl_exec($curlHandler);
if ($body == false) {
throw new Exception("Unable to curl " . $url . " reason: " . curl_error($curlHandler));
}
$status = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
if ($status != 200) {
throw new ScoopHttpNot200Exception($url, $body, $status);
}
curl_close($curlHandler);
return $body;
} catch (Exception $e) {
curl_close($curlHandler);
throw $e;
}
}
示例13: provideNotEmptyTestData
public function provideNotEmptyTestData()
{
self::$fileResource = tmpfile();
$emptyCountable = new \ArrayObject();
$countable = new \ArrayObject(['not', 'empty']);
return [[null, false], ['', false], ['something', true], [0, false], [1, true], [false, false], [true, true], [[], false], [['not', 'empty'], true], [new \stdClass(), true], [$emptyCountable, false], [$countable, true], [self::$fileResource, true]];
}
示例14: generate
public function generate($log)
{
global $db;
$host = "ftp.mozilla.org";
$hostpos = strpos($this->logURL, $host);
if ($hostpos === false) {
throw new Exception("Log file {$this->logURL} not hosted on {$host}!");
}
$path = substr($this->logURL, $hostpos + strlen($host) + strlen("/"));
$ftpstream = @ftp_connect($host);
if (!@ftp_login($ftpstream, "anonymous", "")) {
throw new Exception("Couldn't connect to Mozilla FTP server.");
}
$fp = tmpfile();
if (!@ftp_fget($ftpstream, $fp, $path, FTP_BINARY)) {
throw new Exception("Log not available at URL {$this->logURL}.");
}
ftp_close($ftpstream);
rewind($fp);
$db->beginTransaction();
$stmt = $db->prepare("\n UPDATE runs_logs\n SET content = :content\n WHERE buildbot_id = :id AND type = :type;");
$stmt->bindParam(":content", $fp, PDO::PARAM_LOB);
$stmt->bindParam(":id", $log['_id']);
$stmt->bindParam(":type", $log['type']);
$stmt->execute();
$db->commit();
fclose($fp);
}
示例15: crudHttp
public static function crudHttp($uri, $data, $header = array())
{
$ch = curl_init();
if (isset($data['get']) && !empty($data['get'])) {
$uri .= '?' . http_build_query($data['get']);
}
if (isset($data['post']) && !empty($data['post'])) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data['post']);
}
if (isset($data['put']) && !empty($data['put'])) {
$str = stripslashes(http_build_query($data['put']));
$tmp_file = tmpfile();
fwrite($tmp_file, $str);
fseek($tmp_file, 0);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $tmp_file);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($str));
}
if (isset($data['delete']) && !empty($data['delete'])) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data['delete']);
}
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}