1

我在这里查看了 symfony2 API 文档,

Symfony\Component\Filesystem\Filesystem 中提供的文件系统功能很少

我使用了“ mkdir ”,效果很好,但是无法使用“ exists ”功能

public Boolean exists(string|array|Traversable $files)

它给出了错误

Fatal error: Call to undefined function Survey\BlogBundle\Controller\exists()
4

2 回答 2

2

你确定不是

bool file_exists ( string $filename )

http://php.net/manual/de/function.file-exists.php


查看文档,我发现有一个存在函数。所以也许你错过了添加使用声明

use Symfony\Component\Filesystem\Filesystem;

但是您仍然可以使用file_exists


关于如何使用文件系统的详细信息http://symfony.com/doc/master/components/filesystem.html

2.1 版新功能:文件系统组件是 Symfony 2.1 的新功能。以前,Filesystem 类位于 HttpKernel 组件中。

于 2013-02-16T06:59:37.740 回答
0

在 Symfony 5 中,它确实有效。看起来它需要一个文件数组。

use Symfony\Component\Filesystem\Filesystem;

$fsObject = new Filesystem();
 if ($fsObject->exists(['path/to/file/filename'])){
     //Do something
 }
于 2020-05-12T21:16:14.410 回答