From 6f1f4d2ee94c3dc0bfae344bdcf0193a621e1b4f Mon Sep 17 00:00:00 2001 From: erikn69 Date: Fri, 5 Apr 2024 12:37:50 -0500 Subject: [PATCH] Add PHP file_exists (#461) * Add PHP file_exists * Update src/php/filesystem/file_exists.js --------- Co-authored-by: Kevin van Zonneveld --- src/php/filesystem/file_exists.js | 11 +++++++++++ src/php/filesystem/index.js | 1 + 2 files changed, 12 insertions(+) create mode 100644 src/php/filesystem/file_exists.js diff --git a/src/php/filesystem/file_exists.js b/src/php/filesystem/file_exists.js new file mode 100644 index 0000000000..00bbe64f37 --- /dev/null +++ b/src/php/filesystem/file_exists.js @@ -0,0 +1,11 @@ +module.exports = function file_exists(filename) { + // discuss at: https://locutus.io/php/file_exists/ + // original by: Erik Niebla + // note 1: so this function is Node-only + // example 1: file_exists('test/never-change.txt') + // returns 1: true + + const fs = require('fs') + + return fs.existsSync(filename) +} diff --git a/src/php/filesystem/index.js b/src/php/filesystem/index.js index d70d22615b..71686ed7f5 100644 --- a/src/php/filesystem/index.js +++ b/src/php/filesystem/index.js @@ -1,5 +1,6 @@ module.exports.basename = require('./basename') module.exports.dirname = require('./dirname') +module.exports.file_exists = require('./file_exists') module.exports.file_get_contents = require('./file_get_contents') module.exports.pathinfo = require('./pathinfo') module.exports.realpath = require('./realpath')