Vinee
Vinee

Reputation: 1654

How to use file system function 'exists' in symfony2?

I checked symfony2 API docs here,

Few File system functions are available in Symfony\Component\Filesystem\Filesystem

i used 'mkdir' and it worked fine but, unable to use 'exists' function

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

It gives error

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

Upvotes: 1

Views: 2826

Answers (2)

tlarson
tlarson

Reputation: 473

In Symfony 5, it does work. It looks like it requires an array for files.

use Symfony\Component\Filesystem\Filesystem;

$fsObject = new Filesystem();
 if ($fsObject->exists(['path/to/file/filename'])){
     //Do something
 }

Upvotes: 0

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70466

Are you sure it is not

bool file_exists ( string $filename )

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


Looking at the docs I see that there is an exists function. So maybe you have missed to add a use statement

use Symfony\Component\Filesystem\Filesystem;

However you can still use file_exists


Detailed information on how to use filesystem http://symfony.com/doc/master/components/filesystem.html

New in version 2.1: The Filesystem Component is new to Symfony 2.1. Previously, the Filesystem class was located in the HttpKernel component.

Upvotes: 2

Related Questions