[ATTACHMENTS] In sendFile, check that file exists or show a custom exception
This commit is contained in:
parent
38cf8f8efe
commit
6d31945401
@ -27,6 +27,7 @@ use App\Entity\Attachment;
|
||||
use App\Util\Common;
|
||||
use App\Util\Exception\ClientException;
|
||||
use App\Util\Exception\NoSuchFileException;
|
||||
use App\Util\Exception\ServerException;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
|
||||
use Symfony\Component\HttpFoundation\HeaderUtils;
|
||||
@ -95,6 +96,7 @@ class GSFile
|
||||
*/
|
||||
public static function sendFile(string $filepath, string $mimetype, ?string $output_filename, string $disposition = 'inline'): Response
|
||||
{
|
||||
if (is_file($filepath)) {
|
||||
$response = new BinaryFileResponse(
|
||||
$filepath,
|
||||
Response::HTTP_OK,
|
||||
@ -113,6 +115,9 @@ class GSFile
|
||||
$response->trustXSendfileTypeHeader();
|
||||
}
|
||||
return $response;
|
||||
} else {
|
||||
throw new ServerException(_m('This attachment is not stored locally'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user