PHPackages                             dragonrun1/file\_path\_normalizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dragonrun1/file\_path\_normalizer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dragonrun1/file\_path\_normalizer
=================================

File\_path\_normalizer is a class used to normalize PHP file paths without several of the shortcomings of the built-in functions.

2.1.1(7y ago)33.3k32GPL-2.0PHPPHP &gt;=7.1 &lt;7.4

Since Nov 18Pushed 7y ago3 watchersCompare

[ Source](https://github.com/Dragonrun1/file_path_normalizer)[ Packagist](https://packagist.org/packages/dragonrun1/file_path_normalizer)[ RSS](/packages/dragonrun1-file-path-normalizer/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (9)Used By (2)

README.md
=========

[](#readmemd)

Master: [![Build Status](https://camo.githubusercontent.com/f7ebbcd0d704d382ce00ae1c7e22f5cc0f4a342efd8256197f72646c86064247/68747470733a2f2f7472617669732d63692e6f72672f447261676f6e72756e312f66696c655f706174685f6e6f726d616c697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Dragonrun1/file_path_normalizer)

Master: [![Coverage Status](https://camo.githubusercontent.com/8318069ce26b0e22041a6f88a6a5e60928f4e88f4670f987306e1d077ab8d49a/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f447261676f6e72756e312f66696c655f706174685f6e6f726d616c697a65722e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/Dragonrun1/file_path_normalizer?branch=master)

File\_path\_normalizer is a class used to normalize PHP file paths without several of the shortcomings of the built-in functions.

Why you should use it
---------------------

[](#why-you-should-use-it)

So you maybe wondering why a class like this is even needed since PHP has many built-in functions that let you do almost anything needed to clean up a given file name and path. PHP does have many functions that are made to work with paths and file names plus a wide range of string and regex functions that can be useful, however there are many edge cases and limitations in these functions can lead to bugs and, in the case of any web based applications, possible security issues when parts of the filesystem are unexpectedly exposed.

Just like in a web page where you must protect from Javascript XSS and possible database exposure, you must also ensure where user input might be used to form file system paths or names that it is clean and not doing something unexpected.

Even if you are not forming paths using any user input the OS you use for PHP affects the file path and how many of the file functions work. Probably one of the best know differences is the use of back-slashes and drive letters in Windows paths vs forward slashes and the unified file paths of Linux/Unix and Mac OS X.

Below are some examples to make the issues clearer.

Issue Examples
--------------

[](#issue-examples)

*NOTE: The examples used here are to in no way be considered well written code that should be actually used in your own code but are made to be as simple as possible while showing some of the possible issues.*

```
