webCOMAND

request::filename()

Retrieve the original filename of a file uploaded through an HTTP (or HTTPS) POST.

Prototype

string filename(string $key = NULL, array $options = [])

Parameters

  • key - Name of the file input to retrieve the filename for.  If NULL or no key is provided, an associative array of all filenames will be returned.
  • options - An associative array of zero or more of the following key/value pairs.
    • default - The default value to return if the key is not found.

Return

If the file input exists and a file was uploaded, the filename is returned as a string.  Otherwise, the default values specified in options is returned, or if no default is specified, FALSE.

Example

The following HTML form will POST a file with the key "upload".

<html>
<body>
    <h1>File Upload</h1>
    <form method="POST" enctype="multipart/form-data">
        <input name="upload" type="file" />
        <input type="submit" />
    </form>
</body>
</html>

The following PHP code will retrieve the posted file.

// retrieve the value of the "form" GET parameter
// and "search" POST parameter
$request = new \io_comand_web\request();
$filename = $request->filename('upload');
$filedata = $request->file('upload');