security_helper.php
This file is part of CodeIgniter 4 framework.
(c) CodeIgniter Foundation admin@codeigniter.com
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
Table of Contents
Functions
- sanitize_filename() : string
- Sanitize Filename
- strip_image_tags() : string
- Replaces image tags with their raw src values.
- encode_php_tags() : string
- Convert PHP tags to entities
Functions
sanitize_filename()
Sanitize Filename
sanitize_filename(string $filename[, bool $relativePath = false ]) : string
Tries to sanitize filenames in order to prevent directory traversal attempts and other security threats, which is particularly useful for files that were supplied via user input.
If it is acceptable for the user input to include relative paths, e.g. file/in/some/approved/folder.txt, you can set the second optional parameter, $relativePath to TRUE. Only forward slashes are preserved, backslashes are always removed.
Parameters
- $filename : string
-
Input file name
- $relativePath : bool = false
-
Whether to preserve paths
Return values
stringstrip_image_tags()
Replaces image tags with their raw src values.
strip_image_tags(string $str) : string
If tag replacement fails or the iteration limit is reached, remaining "<img" prefixes are escaped as "<img".
This function does not sanitize HTML. Escape the result appropriately when displaying it as text.
Parameters
- $str : string
Return values
stringencode_php_tags()
Convert PHP tags to entities
encode_php_tags(string $str) : string
Parameters
- $str : string