PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / file-util / src / FileExistsUsingExec.php

FileExistsUsingExec.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/rosell-dk/file-util/src/FileExistsUsingExec.php

41 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FileUtil;
4
5 use ExecWithFallback\ExecWithFallback;
6
7 /**
8 * A fileExist implementation using exec()
9 *
10 * @package FileUtil
11 * @author Bjørn Rosell <[email protected]>
12 */
13 class FileExistsUsingExec
14 {
15
16 /**
17 * A fileExist based on an exec call.
18 *
19 * @throws \Exception If exec cannot be called
20 * @return boolean|null True if file exists. False if it doesn't.
21 */
22 public static function fileExists($path)
23 {
24 if (!ExecWithFallback::anyAvailable()) {
25 throw new \Exception(
26 'cannot determine if file exists using exec() or similar - the function is unavailable'
27 );
28 }
29
30 // Lets try to find out by executing "ls path/to/cwebp"
31 ExecWithFallback::exec('ls ' . $path, $output, $returnCode);
32 if (($returnCode == 0) && (isset($output[0]))) {
33 return true;
34 }
35
36 // We assume that "ls" command is general available!
37 // As that failed, we can conclude the file does not exist.
38 return false;
39 }
40 }
41