mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
[Fix issue #104] - Show image attachements on browser
This commit is contained in:
parent
ce3d2a249b
commit
43ef3e4e19
@ -19,9 +19,9 @@ class FileDownloader extends FileManager {
|
|||||||
|
|
||||||
if(file_exists($fullFilePath) && is_file($fullFilePath)) {
|
if(file_exists($fullFilePath) && is_file($fullFilePath)) {
|
||||||
header('Cache-control: private');
|
header('Cache-control: private');
|
||||||
header('Content-Type: application/octet-stream');
|
header('Content-Type: ' . $this->getFileContentType());
|
||||||
header('Content-Length: '.filesize($fullFilePath));
|
header('Content-Length: ' . filesize($fullFilePath));
|
||||||
header('Content-Disposition: filename='. $this->getFileName());
|
header('Content-Disposition: filename=' . $this->getFileName());
|
||||||
|
|
||||||
flush();
|
flush();
|
||||||
$file = fopen($fullFilePath, 'r');
|
$file = fopen($fullFilePath, 'r');
|
||||||
@ -37,4 +37,18 @@ class FileDownloader extends FileManager {
|
|||||||
public function eraseFile() {
|
public function eraseFile() {
|
||||||
unlink($this->getLocalPath() . $this->getFileName());
|
unlink($this->getLocalPath() . $this->getFileName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function getFileContentType() {
|
||||||
|
$fileExtension = substr($this->getFileName(), -3);
|
||||||
|
$contentTypes = [
|
||||||
|
'jpg' => 'image/jpeg',
|
||||||
|
'gif' => 'image/fig',
|
||||||
|
'png' => 'image/png',
|
||||||
|
'default' => 'application/octet-stream',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $contentTypes[
|
||||||
|
array_key_exists($fileExtension, $contentTypes) ? $fileExtension : 'default'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user