本文整理汇总了PHP中SplFileObject::fpassthru方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::fpassthru方法的具体用法?PHP SplFileObject::fpassthru怎么用?PHP SplFileObject::fpassthru使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::fpassthru方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getContents
/**
* Returns the contents of the file
*
* @return string the contents of the file
*/
public function getContents()
{
$file = new \SplFileObject($this->getRealpath(), 'rb');
ob_start();
$file->fpassthru();
return ob_get_clean();
}
示例2: loadAction
/**
* @Route("/download/{filename}/{file}", name="app_download")
* @Route("/load/{filename}/{file}", name="app_load")
* @ParamConverter("file", converter="file_converter")
* @Method("GET")
* @param string $filename
* @param \SplFileObject $file
* @return Response
*/
public function loadAction($filename, \SplFileObject $file)
{
$response = new Response($file->fpassthru());
$response->headers->set('Content-Type', 'octet/stream');
$response->headers->set('Content-disposition', 'attachment; filename="' . $filename . '.' . $file->getExtension() . '";"');
$response->headers->set('Content-Length', $file->getSize());
$response->headers->set('Cache-Control', 'max-age=31536000, public');
// 1 year
$response->sendHeaders();
return $response->send();
}
示例3: download
public function download($path)
{
if (is_null($path) || empty($path)) {
throw new InvalidArgumentException('You must specify the item to download.', 400);
} else {
if (!$this->exists($path) || !is_file($this->realRootDirectory . DIRECTORY_SEPARATOR . $path)) {
throw new FileNotFoundException('The specified file does not exist.', 404);
}
}
$fileObject = new \SplFileObject($this->realRootDirectory . DIRECTORY_SEPARATOR . $path);
HttpResponse::setContentDisposition($fileObject->getBasename());
HttpResponse::setContentType('application/octet-stream');
HttpResponse::setHeader('Content-Length', $fileObject->getSize());
$fileObject->fpassthru();
exit(0);
}
示例4: explode
$versionPieces = explode(' ', $version);
$phalconVersion = $versionPieces[0];
define('EXAMPLES_DIR', sprintf("%s/%s/%s", dirname(__DIR__), 'interfaces', $phalconVersion));
$phalconClasses = new \RegexIterator(new \ArrayIterator(get_declared_interfaces()), '/^Phalcon/');
foreach ($phalconClasses as $phalconClass) {
$reflector = new \ReflectionClass($phalconClass);
$distillate = new Distillate();
$distillate->setInterfaceName($phalconClass);
$distillate->setExtendingInterfaces(implode(',\\', $reflector->getInterfaceNames()));
$parentClass = $reflector->getParentClass();
if ($parentClass) {
$distillate->addParentClass($reflector->getParentClass()->getName());
}
$methodIterator = new \ArrayIterator($reflector->getMethods());
foreach ($methodIterator as $method) {
$distillate->addMethod($method);
}
$consts = $reflector->getConstants();
$distillate->addConsts($consts);
$fileName = sprintf('%s/%s.php', EXAMPLES_DIR, str_replace('\\', '/', $phalconClass));
$fileName = str_replace('/Phalcon/', '/', $fileName);
$dirName = dirname($fileName);
is_dir($dirName) ?: mkdir($dirName, 0777, true);
$file = new \SplFileObject($fileName, 'w');
//$file = new \SplTempFileObject( );
$writer = new Distillate\Writer($file, true);
$writer->writeToFile($distillate);
$file->rewind();
$file->fpassthru();
echo $fileName . PHP_EOL;
}
示例5: SplFileObject
<?php
$obj = new SplFileObject(dirname(__FILE__) . '/SplFileObject_testinput.csv');
$obj->fpassthru();