# wp-optimize/4.7.0/vendor/rosell-dk/file-util/src/FileExistsUsingExec.php

WP-Optimize – Cache, Compress images, Minify &amp; Clean database to boost page speed &amp; performance, version 4.7.0. 41 lines.

- Page: https://pluginprobe.com/plugins/wp-optimize/4.7.0/code/vendor/rosell-dk/file-util/src/FileExistsUsingExec.php
- Raw: https://pluginprobe.com/plugins/wp-optimize/4.7.0/raw/vendor/rosell-dk/file-util/src/FileExistsUsingExec.php
- Modified: 2022-06-03T18:20:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-optimize/4.7.0/code/vendor/rosell-dk/file-util/src/FileExistsUsingExec.php#L10-L20`.

```php
<?php

namespace FileUtil;

use ExecWithFallback\ExecWithFallback;

/**
 * A fileExist implementation using exec()
 *
 * @package    FileUtil
 * @author     Bjørn Rosell <it@rosell.dk>
 */
class FileExistsUsingExec
{

    /**
     * A fileExist based on an exec call.
     *
     * @throws \Exception  If exec cannot be called
     * @return boolean|null  True if file exists. False if it doesn't.
     */
    public static function fileExists($path)
    {
        if (!ExecWithFallback::anyAvailable()) {
            throw new \Exception(
                'cannot determine if file exists using exec() or similar - the function is unavailable'
            );
        }

        // Lets try to find out by executing "ls path/to/cwebp"
        ExecWithFallback::exec('ls ' . $path, $output, $returnCode);
        if (($returnCode == 0) && (isset($output[0]))) {
            return true;
        }

        // We assume that "ls" command is general available!
        // As that failed, we can conclude the file does not exist.
        return false;
    }
}

```
