Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

How to clean file name for security reasons in PHP?

$
0
0
  1. /**
  2.          * Clean the file name for security
  3.          *
  4.          * @access      public
  5.          * @param       string
  6.          * @return      string
  7.          */           
  8.         function clean_file_name($filename)
  9.         {
  10.                 $bad=array(
  11.                                                 "<!--",
  12.                                                 "-->",
  13.                                                 "'",
  14.                                                 "<",
  15.                                                 ">",
  16.                                                 '"',
  17.                                                 '&',
  18.                                                 '$',
  19.                                                 '=',
  20.                                                 ';',
  21.                                                 '?',
  22.                                                 '/',
  23.                                                 "%20",
  24.                                                 "%22",
  25.                                                 "%3c",          // <
  26.                                                 "%253c",       // <
  27.                                                 "%3e",         // >
  28.                                                 "%0e",         // >
  29.                                                 "%28",         // (
  30.                                                 "%29",         // )
  31.                                                 "%2528",       // (
  32.                                                 "%26",         // &
  33.                                                 "%24",         // $
  34.                                                 "%3f",         // ?
  35.                                                 "%3b",         // ;
  36.                                                 "%3d"          // =
  37.                                         );
  38.                                        
  39.                 $filename=str_replace($bad,'',$filename);
  40.  
  41.                 returnstripslashes($filename);
  42.         }

Viewing all articles
Browse latest Browse all 178

Latest Images

Trending Articles



Latest Images