Example #1
0
 /**
  * @param string $filename
  * @return FileUpload
  */
 public static function fileUploadFromFile($filename)
 {
     if (!file_exists($filename)) {
         throw new FileNotExistsException("File '{$filename}' does not exists");
     }
     $file = new \SplFileInfo($filename);
     return new FileUpload(['name' => $file->getBasename(), 'type' => $file->getType(), 'size' => $file->getSize(), 'tmp_name' => $filename, 'error' => 0]);
 }
Example #2
0
 /**
  * Returns the details about Communicator (current) file
  * w/o any kind of verification of file existance
  *
  * @param string $fileGiven
  * @return array
  */
 protected function getFileDetailsRaw($fileGiven)
 {
     $info = new \SplFileInfo($fileGiven);
     $aFileBasicDetails = ['File Extension' => $info->getExtension(), 'File Group' => $info->getGroup(), 'File Inode' => $info->getInode(), 'File Link Target' => $info->isLink() ? $info->getLinkTarget() : '-', 'File Name' => $info->getBasename('.' . $info->getExtension()), 'File Name w. Extension' => $info->getFilename(), 'File Owner' => $info->getOwner(), 'File Path' => $info->getPath(), 'Name' => $info->getRealPath(), 'Type' => $info->getType()];
     $aDetails = array_merge($aFileBasicDetails, $this->getFileDetailsRawStatistic($info, $fileGiven));
     ksort($aDetails);
     return $aDetails;
 }
Example #3
0
/**
 * Retrieve directory content, directories and files
 *
 * @param Application $app Silex Application
 * @param Request $request Request parameters
 *
 * @return JsonResponse Array of objects
 */
function get_content(Application $app, Request $request)
{
    $dirpath = Utils\check_path($app['cakebox.root'], $request->get('path'));
    if (!isset($dirpath)) {
        $app->abort(400, "Missing parameters");
    }
    $finder = new Finder();
    $finder->followLinks()->depth('< 1')->in("{$app['cakebox.root']}/{$dirpath}")->ignoreVCS(true)->ignoreDotFiles($app['directory.ignoreDotFiles'])->notName($app["directory.ignore"])->sortByType();
    $dirContent = [];
    foreach ($finder as $file) {
        if ($file->isLink()) {
            $linkTo = readlink("{$app['cakebox.root']}/{$dirpath}/{$file->getBasename()}");
            if (file_exists($linkTo) == false) {
                continue;
            }
            $file = new \SplFileInfo($linkTo);
        }
        $pathInfo = [];
        $pathInfo["name"] = $file->getBasename();
        $pathInfo["type"] = $file->getType();
        $pathInfo["mtime"] = $file->getMTime();
        $pathInfo["size"] = Utils\get_size($file);
        $pathInfo["access"] = str_replace('%2F', '/', rawurlencode("{$app['cakebox.access']}/{$dirpath}/{$file->getBasename()}"));
        $pathInfo["extraType"] = "";
        $ext = strtolower($file->getExtension());
        if (in_array($ext, $app["extension.video"])) {
            $pathInfo["extraType"] = "video";
        } else {
            if (in_array($ext, $app["extension.audio"])) {
                $pathInfo["extraType"] = "audio";
            } else {
                if (in_array($ext, $app["extension.image"])) {
                    $pathInfo["extraType"] = "image";
                } else {
                    if (in_array($ext, $app["extension.archive"])) {
                        $pathInfo["extraType"] = "archive";
                    } else {
                        if (in_array($ext, $app["extension.subtitle"])) {
                            $pathInfo["extraType"] = "subtitle";
                        }
                    }
                }
            }
        }
        array_push($dirContent, $pathInfo);
    }
    return $app->json($dirContent);
}
Example #4
0
 /**
  * Converts a SplFileInfo to a Model
  *
  * @param \SplFileInfo $aFile
  *
  * @return Model
  */
 public static function fileToModel(\SplFileInfo $aFile)
 {
     $model = new \stdClass();
     $model->{'dir'} = $aFile->isDir();
     $model->{'extension'} = $aFile->getExtension();
     $model->{'filename'} = $aFile->getFilename();
     $model->{'path'} = str_replace('\\', '/', $aFile->getPathname());
     if ($aFile->isReadable()) {
         $model->{'last_modified'} = $aFile->getMTime();
         $model->{'size'} = $aFile->getSize();
         $model->{'type'} = $aFile->getType();
     }
     return $model;
 }
Example #5
0
            } else {
                //TODO not sure if this is needed!
                if ($key != 'files' && $key != 'dirs') {
                    $f2s = $key . '/' . $val;
                    if (substr($f2s, -3) == 'php') {
                        $output .= 'File: ' . $f2s . PHP_EOL;
                    }
                }
            }
        }
    } else {
        $info = new SplFileInfo($o2s);
        $perms = substr(sprintf('%o', $info->getPerms()), -4);
        $owner = $info->getOwner();
        $group = $info->getGroup();
        $type = $info->getType();
        $size = $info->getSize();
        $scanner = new Scanner($o2s, $eol, $htmlMode, $scannerOptions);
        $scanner->scanFile("all", $patternData, $stringData);
        if (count($scanner->found)) {
            foreach ($scanner->found as $l) {
                $found .= $l;
            }
        } else {
            $found = '';
        }
        //make human readable size
        $size = $scanner->size_readable($size);
    }
} else {
    $ainfo = "The file/folder {$bS}{$o2s}{$bE} does not exist";
Example #6
0
 public function testDecoratedMethods()
 {
     $decorated = $this->getMockBuilder('hanneskod\\classtools\\Tests\\MockSplFileInfo')->setConstructorArgs([''])->getMock();
     $decorated->expects($this->once())->method('getRelativePath');
     $decorated->expects($this->once())->method('getRelativePathname');
     $decorated->expects($this->once())->method('getContents');
     $decorated->expects($this->once())->method('getATime');
     $decorated->expects($this->once())->method('getBasename');
     $decorated->expects($this->once())->method('getCTime');
     $decorated->expects($this->once())->method('getExtension');
     $decorated->expects($this->once())->method('getFileInfo');
     $decorated->expects($this->once())->method('getFilename');
     $decorated->expects($this->once())->method('getGroup');
     $decorated->expects($this->once())->method('getInode');
     $decorated->expects($this->once())->method('getLinkTarget');
     $decorated->expects($this->once())->method('getMTime');
     $decorated->expects($this->once())->method('getOwner');
     $decorated->expects($this->once())->method('getPath');
     $decorated->expects($this->once())->method('getPathInfo');
     $decorated->expects($this->once())->method('getPathname');
     $decorated->expects($this->once())->method('getPerms');
     $decorated->expects($this->once())->method('getRealPath');
     $decorated->expects($this->once())->method('getSize');
     $decorated->expects($this->once())->method('getType');
     $decorated->expects($this->once())->method('isDir');
     $decorated->expects($this->once())->method('isExecutable');
     $decorated->expects($this->once())->method('isFile');
     $decorated->expects($this->once())->method('isLink');
     $decorated->expects($this->once())->method('isReadable');
     $decorated->expects($this->once())->method('isWritable');
     $decorated->expects($this->once())->method('openFile');
     $decorated->expects($this->once())->method('setFileClass');
     $decorated->expects($this->once())->method('setInfoClass');
     $decorated->expects($this->once())->method('__toString')->will($this->returnValue(''));
     $fileInfo = new SplFileInfo($decorated);
     $fileInfo->getRelativePath();
     $fileInfo->getRelativePathname();
     $fileInfo->getContents();
     $fileInfo->getATime();
     $fileInfo->getBasename();
     $fileInfo->getCTime();
     $fileInfo->getExtension();
     $fileInfo->getFileInfo();
     $fileInfo->getFilename();
     $fileInfo->getGroup();
     $fileInfo->getInode();
     $fileInfo->getLinkTarget();
     $fileInfo->getMTime();
     $fileInfo->getOwner();
     $fileInfo->getPath();
     $fileInfo->getPathInfo();
     $fileInfo->getPathname();
     $fileInfo->getPerms();
     $fileInfo->getRealPath();
     $fileInfo->getSize();
     $fileInfo->getType();
     $fileInfo->isDir();
     $fileInfo->isExecutable();
     $fileInfo->isFile();
     $fileInfo->isLink();
     $fileInfo->isReadable();
     $fileInfo->isWritable();
     $fileInfo->openFile();
     $fileInfo->setFileClass();
     $fileInfo->setInfoClass();
     (string) $fileInfo;
 }
Example #7
0
 public function properties($path)
 {
     $path = $this->preparePath($path);
     $file = new \SplFileInfo($path);
     $data['Name'] = $file->getFileName();
     $data['Type'] = $file->getType();
     $data['Size'] = $file->getSize() . ' b';
     $data['Location'] = $this->fileSystem->makePathRelative(pathinfo($file->getRealPath(), PATHINFO_DIRNAME), $this->root);
     return $data;
 }
Example #8
0
<?php

include __DIR__ . '/../../../test/sample_dir/fix_mtimes.inc';
$info = new SplFileInfo(__DIR__ . '/../../sample_dir');
if (!$info->isFile()) {
    echo $info->getRealPath();
}
$info = new SplFileInfo(__DIR__ . '/../../sample_dir/file');
var_dump($info->getbaseName());
var_dump($info->getbaseName('.cpp'));
$info->getCTime();
$info->getGroup();
$info->getInode();
$info->getMTime();
$info->getOwner();
$info->getPerms();
$info->getSize();
$info->getType();
$info->isDir();
$info->isFile();
$info->isLink();
$info->isReadable();
$info->isWritable();
Example #9
0
<?php

$info = new SplFileInfo('SplFileInfo.php');
printf("Extension: %s\n", $info->getExtension());
printf("Filename: %s\n", $info->getFilename());
printf("Path: %s\n", $info->getPathname());
printf("RealPath: %s\n", $info->getRealPath());
printf("Type: %s\n", $info->getType());
printf("Size: %s\n", $info->getSize());
printf("Dir: %b, Exec: %b, File: %b, Link: %b, R: %b, W: %b\n", $info->isDir(), $info->isExecutable(), $info->isFile(), $info->isLink(), $info->isReadable(), $info->isWritable());
$file = $info->openFile('r');
foreach ($file as $line) {
    printf("%s", $line);
}
<?php

$file = new SplFileInfo('spl_file_info.php');
print 'Nome: ' . $file->getFileName() . '<br>' . PHP_EOL;
print 'Extensão: ' . $file->getExtension() . '<br>' . PHP_EOL;
print 'Tamanho: ' . $file->getSize() . '<br>' . PHP_EOL;
print 'Caminho: ' . $file->getRealPath() . '<br>' . PHP_EOL;
print 'Tipo: ' . $file->getType() . '<br>' . PHP_EOL;
print 'Gravação: ' . $file->isWritable() . '<br>' . PHP_EOL;
Example #11
0
 /**
 *@version 1.0
 *@author Rolando Arriaza , ultima version
 *@todo Funcion para crear un arbol de archivos
 *@param string $directory directorio donde comenzara el arbol
 *@param string|array patron en cual el archivo debe respetar
 *@example  
 * <code>
 *   buscaremos los archivos que inicien en dashboard como dashboard.php o dashboard_img.jpg
 *   $pattern = "dashboard"
 * 
 *   busca archivos con el nombre inicial dashboard y extencion php
 *   $pattern = array("name"=>"dashboard" , "extend"=>"php");
        $pattern = array("name"=>"dashboard" , "extend"=>"php" , "pattern"=>false);
 * </code>
 *@return bool | array false si no existe directorio 
 */
 public function FindDataDirectory($directory, $pattern = null)
 {
     if (!is_dir($directory)) {
         return false;
     }
     $object = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::SELF_FIRST);
     if (SivarApi\Tools\Validation::Is_Empty_OrNull($pattern)) {
         foreach ($object as $key => $value) {
             $class = new SplFileInfo($key);
             if ($class->getType() == "file") {
                 $filename = $class->getFilename();
                 $path = $class->getPath();
                 array_push($this->array_dir, array("root" => $path, "filename" => $filename));
             }
         }
     } else {
         $preg = null;
         if (is_array($pattern)) {
             if (isset($pattern['pattern'])) {
                 $p = $pattern["name"];
                 $ext = $pattern["extend"];
                 $preg = "/^({$p}\\.{$ext})\$/";
             } else {
                 $p = $pattern["name"];
                 $ext = $pattern["extend"];
                 $preg = "/^({$p}\\w+\\.{$ext})\$/";
             }
         } else {
             $preg = "/^({$pattern}\\w+\\.php)\$/";
         }
         foreach ($object as $key => $value) {
             $class = new SplFileInfo($key);
             if ($class->getType() == "file") {
                 $filename = $class->getFilename();
                 $path = $class->getPath();
                 $ext = $class->getExtension();
                 if (preg_match($preg, $filename)) {
                     array_push($this->array_dir, array("root" => $path, "filename" => $filename));
                 }
             }
         }
     }
     return $this->array_dir;
 }
Example #12
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $processHelper = $this->getHelper('process');
     /* @var $processHelper ProcessHelper */
     if ($output instanceof ConsoleOutput) {
         $stderr = $output->getErrorOutput();
     } else {
         $stderr = $output;
     }
     $sshDir = $configHelper->getConfiguration()->getSshDirectory();
     $keyFile = new \SplFileInfo($input->getArgument('key') ?: $sshDir . '/id_rsa-' . sha1(mt_rand() . time()));
     // Check if file already exists
     try {
         $keyFile->getType();
         // Throws if file does not exist.
         throw new FileExistsException($keyFile);
     } catch (\RuntimeException $ex) {
         // noop
     }
     OutsideConfiguredRootDirectoryException::assert($keyFile, 'ssh-dir', $configHelper->getConfiguration()->getSshDirectory());
     $sshKeygen = ProcessBuilder::create(['ssh-keygen', '-q', '-f', $keyFile, '-C', $input->getOption('comment'), '-N', ''])->setTimeout(null)->getProcess();
     $processHelper->mustRun($output, $sshKeygen);
     $stderr->writeln(sprintf('Generated key <info>%s</info>', $keyFile->getPathname()), OutputInterface::VERBOSITY_VERBOSE);
     if ($input->getOption('print-public-key')) {
         $output->write(file_get_contents($keyFile->getPathname() . '.pub'), false, OutputInterface::OUTPUT_RAW | OutputInterface::VERBOSITY_QUIET);
     }
     if ($input->getOption('target-repository')) {
         $this->getApplication()->find('repository:add')->run(new ArrayInput(['repository' => $input->getOption('target-repository'), 'key' => $keyFile->getPathname(), '--alias' => preg_replace('/^id_rsa-/', '', $keyFile->getFilename())]), $output);
     }
 }