Use at own risk. Programs haven't been thoroughly tested.

function: safe_filename

Regex function to generate Filesystem safe filenames Very usefull for upload scripts. Returns a clean filename that cannot frustrate further processing

Info

@author Kevin van Zonneveld
@version 1.0
@link http://kevin.vanzonneveld.net
@param (string) $filename The filename to make safe

Example

Usage
echo(safe_filename("fu@($&cked)     _ UP 'F\"ileName1\"23!!!@#$(&%)'"));

Outputs
fucked_UP_FileName123

Source Code

download source
<?php
function safe_filename($filename){
  
  return preg_replace('/[^a-zA-Z0-9\.\-_]/', '', preg_replace('/([\s_][\s_]*)/',"_",$filename));
}
?>

Add comment

» Currently away on vacation. I can reply your message the 24th of July 2008. Please post anyway and check back then. Thank you!

for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

Comments

No comments. Be the first!