Attachment::getStorageLocation PHP Метод

getStorageLocation() публичный Метод

Get the full path to the storage location of the file on disk.
public getStorageLocation ( ) : string
Результат string
    public function getStorageLocation()
    {
        global $Campsite;
        if (isset($this->m_data['id'])) {
            $storageLocation = $Campsite['FILE_DIRECTORY'] . "/" . $this->getLevel1DirectoryName() . "/" . $this->getLevel2DirectoryName() . "/" . sprintf('%09d', $this->m_data['id']);
        } else {
            $storageLocation = $Campsite['FILE_DIRECTORY'] . "/" . $this->getLevel1DirectoryName() . "/" . $this->getLevel2DirectoryName() . "/" . sprintf('%09d', 0);
        }
        if (isset($this->m_data['extension']) && !empty($this->m_data['extension'])) {
            $storageLocation .= '.' . $this->m_data['extension'];
        }
        return $storageLocation;
    }

Usage Example

Пример #1
0
}
$attachmentId = (int) ltrim($attachment, " 0\t\n\r");
$attachmentObj = new Attachment($attachmentId);
if (!$attachmentObj->exists()) {
    header('HTTP/1.0 404 Not Found');
    echo 'Error 404: File not found';
    exit;
}
header('Content-Type: ' . $attachmentObj->getMimeType());
if ($g_download == 1) {
    header('Content-Disposition: ' . $attachmentObj->getContentDisposition() . '; filename="' . $attachmentObj->getFileName()) . '"';
} else {
    if ($g_show_in_browser == 1) {
        header('Content-Disposition: inline; filename="' . $attachmentObj->getFileName()) . '"';
    } else {
        if (!$attachmentObj->getContentDisposition() && strstr($attachmentObj->getMimeType(), 'image/') && (strstr($_SERVER['HTTP_ACCEPT'], $attachmentObj->getMimeType()) || strstr($_SERVER['HTTP_ACCEPT'], '*/*'))) {
            header('Content-Disposition: inline; filename="' . $attachmentObj->getFileName()) . '"';
        } else {
            header('Content-Disposition: ' . $attachmentObj->getContentDisposition() . '; filename="' . $attachmentObj->getFileName()) . '"';
        }
    }
}
header('Content-Length: ' . $attachmentObj->getSizeInBytes());
$filePath = $attachmentObj->getStorageLocation();
if (file_exists($filePath)) {
    readfile($filePath);
} else {
    header('HTTP/1.0 404 Not Found');
    echo 'Error 404: File not found';
    exit;
}
All Usage Examples Of Attachment::getStorageLocation