# perldoc > CGI::Session::Driver::file

yaml
---
type: CommandReference
command: CGI::Session::Driver::file
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `CGI::Session->new()` — uses file driver by default
- `CGI::Session->new("driver:file", $sid)` — specify session ID
- `CGI::Session->new("driver:file", $sid, {Directory=>'/tmp'})` — set session directory
- `$CGI::Session::Driver::file::FileName = "%s.dat"` — change session file naming template
- `CGI::Session->new(undef, undef, {UMask=>0600})` — set custom umask for session files
- `CGI::Session->new(undef, undef, {NoFlock=>1})` — disable file locking (risky)

## Name

Default [CGI::Session](https://metacpan.org/pod/CGI::Session) driver – stores session data in plain files.

## Synopsis

perl
$s = CGI::Session->new();
$s = CGI::Session->new("driver:file", $sid);
$s = CGI::Session->new("driver:file", $sid, {Directory=>'/tmp'});
## Options

- `Directory` — location of session files; defaults to `File::Spec->tmpdir()`. Creates directory hierarchy if missing.
- `UMask` — octal umask for session files; default is `0660`.
- `NoFlock` — set to 1 to disable file locking (use with caution). Also settable via `$CGI::Session::Driver::file::NoFlock`.
- `FileName` — global variable `$CGI::Session::Driver::file::FileName` (or `$CGI::Session::File::FileName` for 3.x compat) defining the file naming template; default is `cgisess_%s`.

## Examples

perl
# Basic usage (defaults to file driver)
$s = CGI::Session->new();

# With explicit session ID
$s = CGI::Session->new("driver:file", $sid);

# Custom session directory
$s = CGI::Session->new("driver:file", $sid, {Directory=>'/tmp'});

# Change file naming template
use CGI::Session::Driver::file;
$CGI::Session::Driver::file::FileName = "%s.dat";
$s = CGI::Session->new();
## See Also

- [CGI::Session](https://metacpan.org/pod/CGI::Session) — base module for session management.
- [File::Spec](https://metacpan.org/pod/File::Spec) — used for default temporary directory.
