note 72052 added to ref.filesystem
| From: | designatevoid at gmail dot com | Date: | Sun, 31 Dec 2006 00:17:36 +0000 |
| Subject: | note 72052 added to ref.filesystem | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121121@lists.php.net to get a copy of this message | ||
Here's a function that checks if a string filename, absolute or relative, is valid or not.
<?php
function validFilename($file)
{
if( checkCurrentOS( 'Win' )) {
// if has invalid filename, return false
if ( preg_match( '/PRN|CON|AUX|CLOCK\$|NUL|COM\d|LPT\d/i', $file)) {
return false;
}
$parts = explode( "\\", $file);
// if a drive letter, approve (don't check it later)
if (preg_match( '/[A-Za-z]:/', $parts[0] )) {
$parts[0] = null;
}
// checks for invalid printable charactors or control charactors
foreach ($parts as $part) {
if( preg_match( '|[\^\|\?\*<\":>/\a\b\e\f\n\r\t]|', $part )) {
return false;
}
}
return true;
} else { // unix always passes
return true;
}
}
function checkCurrentOS($operatingSystem)
{
$currentOS = substr( php_uname(), 0, 7 ) == "Windows" ? "Win" :
"_Nix";
if ( strcmp( $operatingSystem, $currentOS ) == 0 ) {
return true;
} else {
return false;
}
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 75.7.35.22
----
Manual Page -- http://www.php.net/manual/en/ref.filesystem.php
Edit -- https://master.php.net/note/edit/72052
Del: integrated -- https://master.php.net/note/delete/72052/integrated
Del: useless -- https://master.php.net/note/delete/72052/useless
Del: bad code -- https://master.php.net/note/delete/72052/bad+code
Del: spam -- https://master.php.net/note/delete/72052/spam
Del: non-english -- https://master.php.net/note/delete/72052/non-english
Del: in docs -- https://master.php.net/note/delete/72052/in+docs
Del: other reasons-- https://master.php.net/note/delete/72052
Reject -- https://master.php.net/note/reject/72052
Search -- https://master.php.net/manage/user-notes.php