file($files['upfile']['tmp_name']), array( 'pdf' => 'application/pdf', 'zip' => 'application/zip', 'rar' => 'application/rar', 'txt' => 'text/plain' ), true )) { throw new RuntimeException('Invalid file format.'); } $name = basename($files['upfile']['name']); $name = preg_replace('/[^\x20-\x7E]/', '', $name); if ($name != ".htaccess") { if (!move_uploaded_file( $files['upfile']['tmp_name'], $dir . $name)) { throw new RuntimeException('Failed to move uploaded file.'); } } else { throw new RuntimeException('Invalid filename.'); } return $name; } } ?>