本文整理汇总了PHP中FileSystem类的典型用法代码示例。如果您正苦于以下问题:PHP FileSystem类的具体用法?PHP FileSystem怎么用?PHP FileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("<error>Be carreful, you might removes files you don't want to. You should backup your files beforehand to be sure everything still works as intended.</error>");
$force = $input->getOption('force');
$container = $this->getContainer();
$fs = new FileSystem();
$helper = $this->getHelper('question');
//Parse the file directory and fetch the other directories
//We should find Workspaces and Users. Workspaces being formatted like "WORKSPACE_[ID]
$fileDir = $container->getParameter('claroline.param.files_directory');
$iterator = new \DirectoryIterator($fileDir);
foreach ($iterator as $pathinfo) {
if ($pathinfo->isDir()) {
$name = $pathinfo->getBasename();
//look for workspaces
if (strpos('_' . $name, 'WORKSPACE')) {
$parts = explode('_', $name);
$id = $parts[1];
$workspace = $container->get('claroline.manager.workspace_manager')->getWorkspaceById($id);
if (!$workspace) {
$continue = false;
if (!$force) {
$question = new ConfirmationQuestion('Do you really want to remove the directory ' . $pathinfo->getPathname() . ' [y/n] y ', true);
$continue = $helper->ask($input, $output, $question);
}
if ($continue || $force) {
$fs->remove($pathinfo->getPathname());
}
}
}
}
}
}
示例2: connect
public function connect(Application $app)
{
// creates a new controller based on the default route
$controllers = $app['controllers_factory'];
$names = [];
foreach ($this->faculty->professors as $professor) {
$names[] = $professor->name;
}
$fs = new FileSystem();
$fs->remove($this->faculty->baseCacheDestination);
$names = '(' . implode('|', $names) . ')';
$faculty = $this->faculty;
$controllers->get('/{processor}/{path}', function (Application $app, $processor, $path) use($faculty) {
$exten = [];
preg_match($faculty->extenstions, $path, $exten);
$exten = ltrim($exten[0], '.');
if (empty($exten)) {
return $app->abort(404);
}
$faculty->process($processor, $path);
$imagePath = $faculty->getLastProcessed()[0];
return $app->sendFile($imagePath, 200, array('Content-Type' => 'image/' . $exten));
})->assert('path', $this->faculty->extenstions);
return $controllers;
}
示例3: downloadFileTaskAction
/**
* Serve a file by forcing the download
*
* @Route("/download-task/{id}", name="download_file_task", requirements={"filename": ".+"})
*/
public function downloadFileTaskAction($id)
{
/**
* $basePath can be either exposed (typically inside web/)
* or "internal"
*/
$repository = $this->getDoctrine()->getRepository('TrackersBundle:Project_Task_Attachments');
$files = $repository->find($id);
if (empty($files)) {
throw $this->createNotFoundException();
}
$filename = $files->getFileurl();
$basePath = $this->get('kernel')->getRootDir() . '/../web/upload';
$filePath = $basePath . '/' . $filename;
$name_array = explode('/', $filename);
$filename = $name_array[sizeof($name_array) - 1];
// check if file exists
$fs = new FileSystem();
if (!$fs->exists($filePath)) {
throw $this->createNotFoundException();
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filePath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit;
}
示例4: extractTo
public function extractTo($extractPath, $files = null)
{
$fs = new FileSystem();
$ds = DIRECTORY_SEPARATOR;
for ($i = 0; $i < $this->numFiles; $i++) {
$oldName = parent::getNameIndex($i);
$newName = mb_convert_encoding($this->getNameIndex($i), 'ISO-8859-1', 'CP850,UTF-8');
//we cheat a little because we can't tell wich name the extracted part should have
//so we put it a directory wich share it's name
$tmpDir = $extractPath . $ds . '__claro_zip_hack_' . $oldName;
parent::extractTo($tmpDir, parent::getNameIndex($i));
//now we move the content of the directory and we put the good name on it.
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($tmpDir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isFile()) {
$fs->mkdir(dirname($extractPath . $ds . $oldName));
$fs->rename($item->getPathname(), $extractPath . $ds . $oldName);
}
}
}
//we remove our 'trash here'
$iterator = new \DirectoryIterator($extractPath);
foreach ($iterator as $item) {
if (strpos($item->getFilename(), '_claro_zip_hack')) {
$fs->rmdir($item->getRealPath(), true);
}
}
}
示例5: checkRepositoryExists
private function checkRepositoryExists($path)
{
$fs = new FileSystem();
if (!$fs->exists($path)) {
throw new PayrollRepositoryDoesNotExist(sprintf('Path %s does not exist.', $path));
}
}
示例6: testCleanUp
public function testCleanUp()
{
$fs = new FileSystem();
$fs->dumpFile($this->tmpDir . '/dummy-file', 'Dummy content.');
$dw = new FilesystemDataWriter(new Filesystem(), $this->tmpDir);
$dw->setUp();
$this->assertFileNotExists($this->tmpDir . '/dummy-file');
}
示例7: cleanupClientSpec
public function cleanupClientSpec()
{
$client = $this->getClient();
$command = 'p4 client -d $client';
$this->executeCommand($command);
$clientSpec = $this->getP4ClientSpec();
$fileSystem = new FileSystem($this->process);
$fileSystem->remove($clientSpec);
}
示例8: main
function main()
{
if (false === auth()) {
error("Not logged in", 403);
}
$fs = new FileSystem();
$file = $fs->getOwnFile();
$fs->delete($file);
}
示例9: onKernelTerminate
/**
* @DI\Observe("kernel.terminate")
*/
public function onKernelTerminate(PostResponseEvent $event)
{
if (count($this->elementsToRemove) > 0) {
$fs = new FileSystem();
foreach ($this->elementsToRemove as $element) {
$fs->remove($element);
}
}
}
示例10: loadConfig
/**
* Loads app config from environment source code into $this->config
*/
private function loadConfig()
{
// Look for .director.yml
$fs = new FileSystem();
if ($fs->exists($this->getSourcePath() . '/.director.yml')) {
$this->config = Yaml::parse(file_get_contents($this->getSourcePath() . '/.director.yml'));
} else {
$this->config = NULL;
}
}
示例11: savePsr4s
public static function savePsr4s($vendorDir, $localPsr4Config, $io)
{
$filesystem = new FileSystem();
$psr4File = $filesystem->normalizePath(realpath($vendorDir . self::PSR4_FILE));
if ($localPsr4Config && $psr4File) {
$io->write('generating local autoload_psr4.php ....');
self::appendBeforeLastline($localPsr4Config, $psr4File);
$io->write('local autoload_psr4 generated.');
}
}
示例12: removeModuleFromDisk
public function removeModuleFromDisk($name)
{
$fs = new FileSystem();
try {
$fs->remove(_PS_MODULE_DIR_ . '/' . $name);
return true;
} catch (IOException $e) {
return false;
}
}
示例13: ExtractTemplateFileTags
/**
* Used to get tags within given template file
*
* It reads a template file and extracts all the tags in the template file
*
* @since 1.0.1
* @param string $template_path absolute path to the template html file
*
* @return array $template_information an array with 2 elements.
* first one is the template contents string.
* the second one is the template tag replacement string
*/
function ExtractTemplateFileTags($template_path)
{
/** The filesystem object */
$filesystem_obj = new FileSystem(array());
$template_contents = $filesystem_obj->ReadLocalFile($template_path);
/** All template tags of the form {} are extracted from the template file */
preg_match_all("/\\{(.+)\\}/iU", $template_contents, $matches);
$template_tag_list = $matches[1];
$template_information = array($template_contents, $template_tag_list);
return $template_information;
}
示例14: deleteExistingFile
public function deleteExistingFile($fileIdWithoutExtension, $fileFullPath)
{
$fs = new FileSystem();
if ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.docx')) {
unlink($fileFullPath . $fileIdWithoutExtension . '.docx');
} elseif ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.doc')) {
unlink($fileFullPath . $fileIdWithoutExtension . '.doc');
} elseif ($fs->exists($fileFullPath . $fileIdWithoutExtension . '.pdf')) {
unlink($fileFullPath . $fileIdWithoutExtension . '.pdf');
}
return;
}
示例15: getFile
/**
* Get a File from a hash
* @param [string] $relativePath
* @return File
*/
public function getFile($relativePath)
{
if ($this->fileSystem->exists($this->getPath($relativePath))) {
return new File($this->getPath($relativePath));
}
return false;
}