示例#1
0
 /**
  * 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();
 }
 /**
  * @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
0
 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
0
$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;
}
<?php

$obj = new SplFileObject(dirname(__FILE__) . '/SplFileObject_testinput.csv');
$obj->fpassthru();