I'm not sure that any of those filters are suitable (on their own) for file uploads.
I like this code:
PHP Code:
//Check for valid upload
if($_FILES['image']['error'] != UPLOAD_ERR_OK) {
echo 'Upload file error';
return;
}
//Check for valid upload
if(!is_uploaded_file($_FILES['image']['tmp_name'])) {
echo 'Invalid request';
return;
}
//Sanitize the filename (See note below)
$remove_these = array(' ','`','"','\'','\\','/');
$newname = str_replace($remove_these, '', $_FILES['image']['name']);
//Make the filename unique
$newname = time().'-'.$newname;
//Save the uploaded the file to another location
$upload_path = "/home/mysite/public_html/uploads/$newname";
move_uploaded_file($_FILES['image']['tmp_name'], $upload_path);
found at
phpsense. It's a few years old though (2007) but it's a good page.