SOURCE

FileDownload.php

Classes


FileDownload

class FileDownload

{

Routines to send a file to the browser.
Author: Umberto Salsi <salsi@icosaedro.it>
Copyright: Copyright 2018 by icosaedro.it di Umberto Salsi
Version: $Date: 2018/12/22 23:27:35 $

Class constants


APPLICATION_OCTET_STREAM

public APPLICATION_OCTET_STREAM = "application/octet-stream"

Default generic MIME type for unknown files.

Methods


getFilenameExtension()

public static string getFilenameExtension(string $path)

Returns the extension of the file name. The extension is anything that follows the last dot in the path and containing latin letters, digits and underscore.
Return: Filename extension converted to uppercase letters, or the empty string if no suitable extension is found.


getTypeFromExtension()

public static string getTypeFromExtension(string $ext) throws RuntimeException

Returns a guess for the type of the file based on the given file name extension.
Parameters:
$ext - File name extension, for example "txt".
Return: Corresponding MIME type.


getTypeFromFilename()

public static string getTypeFromFilename(string $filename) throws RuntimeException

Returns a guess for the type of the file based on its filename extension. Note that this function relies only on the file name extension alone, then it does not pretend a corresponding file does actually exist. On the contrary, the standard mime_content_type() does really access the file with that name, which might not really exist (user's submitted files should always be saved under some safe, harmful temporary file name).
Return: Best guessed MIME type of the file.


parseMimeTypesFile()

public static string[string] parseMimeTypesFile(string $path) throws ErrorException

Parses the Apache MIME types file.
Return: Associative array that maps lower-case file name extensions to their corresponding MIME type.


sendFile()

public static void sendFile(string $path) throws ErrorException

Sends the raw content of a file. A previous call to sendHeaders() is recommended if not mandatory to properly set the type and suggested file name.
Parameters:
$path - Path of the file on the server. This name has nothing to do with the name suggested to the user.
Throws:
ErrorException - Failed access to the file system.


sendHeaders()

public static void sendHeaders(string $name, string $type, boolean $isAttachment)

Sends to the browser the headers to send a generic content.
Parameters:
$name - Suggested name of the file, UTF-8 encoded.
$type - MIME type. For "text/plain" and "text/html" PHP automatically adds the default_charset as specified in the configuration file; you may want to override that setting by specifying your own encoding, for example "text/plain; charset=UTF-8".
$isAttachment - True if the browser should prompt the user to save the content locally, rather than display it immediately.


Private properties: $cached_extensions
}

Requirements

PHP Version: 7

Required modules: core, file, pcre, phpinfo, spl

Required packages:

../../../AutoloadException.php
../../../CastException.php
../../../InternalException.php
../../../all.php
../../../autoload.php
../../../cast.php
../../../errors.php
../cast/ArrayBothType.php
../cast/ArrayIntType.php
../cast/ArrayStringType.php
../cast/BooleanType.php
../cast/ClassType.php
../cast/FloatType.php
../cast/IntType.php
../cast/MixedType.php
../cast/NullType.php
../cast/ObjectType.php
../cast/ResourceType.php
../cast/StringType.php
../cast/TypeInterface.php
../cast/Types.php
../containers/Printable.php

Generated by PHPLint Documentator